Send emails via ESP8266

Hello everyone

in a previous contribution I showed how an ESP processor can send and receive ping packets. Today I want to show that this is also possible with SMTP via GMail. During my research I became aware of a practical library.

Required hardware:

  • NodeMCU with ESP8266

 

Preparatory work:

  • Version check of boar definitions in the board administrator
  • Create a G-Mail account
    • Allow services for "unsafe apps".

I would encourage all our readers to create their own account for this project so as not to jeopardize their account security.

How to create a Google Account Here sufficiently described in order not to have to go into more detail:

Once the account has been created and activated, we can log in to Google and open the settings for the account, you will find this point in the upper right corner of the browser. "G Suite -> Google Account" You can also reach the page by entering the URL from the screenshot:

Navigate as seen above to the point "Security", where you have the possibility to allow access through less secure apps, this access must be activated:

Next, we'll take care of the board definitions in the Arduino IDE

We describe in detail how to put the ESP boards into operation in our e-books. However, this project may require the board definitions to be downgraded to 2.4.2. To do this, we remove the module in the board manager and then re-energise it:

After that, the boards will be available again as usual.

To better deal with different version stands, definitions and libraries, I would like to suggest PlatformIO to the somewhat advanced hobbyist at this point.

The library required for SMTP shipping can be found here for download. We can download this as *.zip and include them in the Arduino IDE under Sketch -> Library -> . Zip library.

The subsequent restart of the Arduino IDE is mandatory.

After the successful import, we have an example in the IDE at: "File -> Examples -> Examples from own libraries -> ESP8266SMTP -> ESP8266SMTP_Gmail.ino" which we still need to customize.

Since the ESP requires a WiFi connection to send an email, we first adjust the SSID and w-lan password in the header.

The next necessary adjustments can be found in the Void loop:

Enter your data in the lower section from SMTP.setEmail. In the first two lines, the user account and password you just created, see . Subject the subject of the email to be sent. In the .setFrom section, you can enter the sender to be displayed when you receive the mail (the real sender remains your new Gmail account).

The next section then determines the recipients and the content of the email:

I have sent an e-mail to info@az-delivery.com for my example, please enter ONE YOUR ADDRESS here. If you have multiple recipients, you can insert them in the same place, separately with a comma.

The second part, here "The European languages....." contains the message of the email to be sent and has been created in the template with a text generator. Here is the result:

For a better understanding, I have changed the block again:

I do not provide the complete code for Copy&Paste today and ask you to use your knowledge wisely.

Until the next post ;)

 

Update 03.02.20:

Blog post reviewed, still works. No beginner's project!
Contact point for advanced users: Turn on debugging in esp8266SMTP.h line 14, pay attention to the version status of the used packages/libraries!

 

Esp-8266Projekte für fortgeschrittene

8 comments

Wolfgang

Wolfgang

Warum wurden hier nicht wie in anderen Beispielen die Acountdaten mit Base64 verschlüsselt?

JB

JB

Hallo,
ich erhalte immer die Fehlermeldung
SMTH AUTH Erro. Wenn ich dann die Änderung von Rolba v. 05.01.20 vornehme
kommt:
WiFiClientSecure has no member setInSecure
Kennt jemand die Ursache und kann weiterhelfen?

Rolba

Rolba

Google hat seine Sicherheitsabfrage geändert, daher folgende Schritte:
1. Librarie ESP8266SMTP.cpp ändern
Code:
WiFiClientSecure client; // Zeile 121
client.setInsecure(); // neuen Eintrag einfügen
2. Google Gmailkonto den Zugriff weniger sicherer Apps erlauben !

LG
Roland

jakob

jakob

ich habe das gleiche problem wie Erhardsson
“Error sending message: Could not connect to mail server”

komme leider nicht weiter. kann es sein, dass hier ein problem mit ssl ist?

andreas

andreas

Hallo
ich möchte anstatt eines Textes, wie hier in deinem Beispiel

if(SMTP.Send(“me8az-delivery.com” Die Lichtschranke an der Vorderseite …."
nicht den Text “Die Lichtschranke…” sondern eine Variable mit einen Wert versenden.
Da aber der SMTP.Send Befehl einen String verlangt, bekomme ich es einfach nicht hin,,,

Kann Du mir sagen wie das geht ?

Jonas

Jonas

Hallo,
erstmal vielen Dank für den Beitrag. Habe es ausprobiert und es hat nach dem Downgrade der Version auch funktioniert. Ich benötige aber die atuellste Version (2.5.0), ich einen Webserver mit einbinden möchte, der aber bei der älteren Version nicht stabil läuft. Gibt es da eventuell noch eine Lösung, dass der E-Mailversand auch auf der aktuellen Version läuft?
Wäre super, wenn mir da jemand weiterhelfen könnte.
Gruß
Jonas

Erhardsson

Erhardsson

Hallo,
ich bekomme immer die Meldung:

“Error sending message: Could not connect to mail server”

Benutzername und Password sind OK.

Was tun?

veit

veit

sehr schön!

notifications an android handys schicken wäre auch fein ….

Leave a comment

All comments are moderated before being published