• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Setting up email for esp32

Q&A Forum › Category: ESP32 › Setting up email for esp32
0 Vote Up Vote Down
Richard Funnell asked 3 years ago

Hi, Please can you help??    Have followed your tutorial on ESP32 Sending Email (text) Used the code from Raw, and set up a new gmail account, selecting 2-step Verification, and generated the 16 piece password, Selecting MAIL as the SELECT APP and Other for SELECT Device. and called it ESP32.  Filled in the WiFi ssid and password, The Author_Email (the new gmail account *****.gmail.com) and placed the generated password in the Author_password section. Typed the hotmail account to receive the email.  Compiled OK and opened the serial monitor, and it won’t accept the account /password. please see below:
Connecting to SMTP server…
> C: ESP Mail Client v2.1.2
> C: connect to SMTP server
> C: host > smtp.gmail.com
> C: port > 465
> C: starting socket
> C: connecting to Server
> C: seeding the random number generator
> C: setting up the SSL/TLS structure
! W: Skipping SSL Verification. INSECURE!
> C: setting hostname for TLS session
> C: performing the SSL/TLS handshake
> C: verifying peer X.509 certificate
> C: smtp server connected
 
SMTP server connected, wait for greeting…
< S: 220 smtp.gmail.com ESMTP b8-20020a05600c4e0800b0038c6c37efc3sm9508368wmq.12 – gsmtp
 
Sending greeting response…
> C: send smtp command, HELO
< S: 250-smtp.gmail.com at your service, [109.148.159.32]
< S: 250-SIZE 35882577
< S: 250-8BITMIME
< S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
< S: 250-ENHANCEDSTATUSCODES
< S: 250-PIPELINING
< S: 250-CHUNKING
< S: 250 SMTPUTF8
 
Logging in…
> C: send smtp command, AUTH PLAIN
> C: rfesp32@gmail.com
> C: rfesp32@gmail.com *******************
< S: 535-5.7.8 Username and Password not accepted. Learn more at
< S: 535 5.7.8  https://support.google.com/mail/?p=BadCredentials b8-20020a05600c4e0800b0038c6c37efc3sm9508368wmq.12 – gsmtp
Error, authentication failed
> E: authentication failed
> C: cleaning SSL connection

9 Answers
0 Vote Up Vote Down
Steve Mercer answered 3 years ago

You can’t have two step verification with an Arduino application. You specifically have to follow GMail’s steps for allowing less secure apps access to your account.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
 
Which project exactly are you trying to follow?
 
We recently updated our tutorials that use Gmail. Gmail requires you to create an app password to allow less secure apps to send emails using your account.
 
Everything is explained in the tutorial. But maybe there are some tutorials that missed the update.
 
This tutorial is updated: https://randomnerdtutorials.com/esp32-send-email-smtp-server-arduino-ide/ See the Create an App Password section.
 
Regards,
Sara
 

0 Vote Up Vote Down
Richard Funnell answered 3 years ago

Thanks for your replies and the link, now set up using 2 step with app password. Found this when setting up my gmail account :
To help keep your account secure, starting May 30, 2022, ​​Google will no longer support the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.
Please note this deadline does not apply to Google Workspace or Google Cloud Identity customers. The enforcement date for these customers will be announced on the Workspace blog at a later date.
For more information, please continue reading.
Special Note on Apple Device Sign-Ins. Users who have not recently signed into their Google Account using only username and password will be able to only make new sign in attempts using the Google account type starting from February 28, 2022. Existing users may continue to sign into their Google Account using their username and password until May 30, 2022.
 
All working now Thank you.

0 Vote Up Vote Down
Richard Funnell answered 3 years ago

Can someone please tell me if it is possible to use a variable between <h>      </h> as in Hello World!
/*Send HTML message*/
String htmlMsg = “<div style=\”color:#2f4468;\”><h1>Hello World!</h1><p>- Sent from ESP board</p></div>”;
 
many thanks

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
Yes. I think it should be possible to use a variable.
Are you having issues with that?
Regards,
Sara

0 Vote Up Vote Down
Richard Funnell answered 3 years ago

yes, I need to run the same code about 12 times at different intervals, (could be days) but I feel that programming the same code 12 times just to change the Hello world part, there must be an easier way. I have put the following code in a Void  Sendmessage() and will be calling it in the Void loop section. I am testing the code in the Void loop with a delay. It works as is, sending me an email every 2-3mins but need to change the Re-order Boswellia part.
Hope that makes sense,   many thanks..
void loop(){
  
 
Sendmessage();
 
 
 
 
delay(200000);
}
 
 
void Sendmessage(){
 
 SMTP_Message message;
 ESP_Mail_Session session;
 
  session.server.host_name = SMTP_HOST;
  session.server.port = SMTP_PORT;
  session.login.email = AUTHOR_EMAIL;
  session.login.password = AUTHOR_PASSWORD;
  session.login.user_domain = “”;
  
  Serial.print(AUTHOR_EMAIL);
  message.sender.name = “ESP”;
  message.sender.email = AUTHOR_EMAIL;
  message.subject = “Tablet Re-Order”;
  message.addRecipient(“ESP32”, RECIPIENT_EMAIL);
 
  //
 
 String htmlMsg = “<div style=\”color:#2f4468;\”><h1>Re-order Boswellia</h1><p>- Sent from ESP board</p></div>”; 
  
  message.html.content = htmlMsg.c_str();
  message.text.charSet = “us-ascii”;
  message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
  
    if (!smtp.connect(&session))
    return;
  if (!MailClient.sendMail(&smtp, &message))
    Serial.println(“Error sending Email, ” + smtp.errorReason());
}

0 Vote Up Vote Down
Richard Funnell answered 3 years ago

I just don’t know how to change it to a variable.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi. 
I also answered your other question: https://rntlab.com/question/esp32-email/#answer-97033
Yes.
You should concatenate your existing string htmlMsg with the variable.
For example:
String yourVariable;
String htmlMsg = “<div style=\”color:#2f4468;\”><h1>" + YourVariable +"</h1><p>- Sent from ESP board</p></div>”;

To learn more about string concatenation, you can read this arduino guide: https://docs.arduino.cc/built-in-examples/strings/StringAdditionOperator.

If you want to use a function, you need to pass the text you want to send as an argument. You need to declare your function as follows:
void Sendmessage(String variable){
(…)
Then, concatenate that variable with the existing HTML variable:

String htmlMsg = “<div style=\”color:#2f4468;\”><h1>" + variable +"</h1><p>- Sent from ESP board</p></div>”;


Then, when you want to send messages, simply call Sendmessage() and set as argument the message. For example:
 

Sendmessage("Re-order Boswellia");

I hope this helps.
 
Regards,
Sara

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

You can also take a look at this project that creates a function to send emails.

ESP32 Email Alert Based on Temperature Threshold (change values on web server)

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.