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.
- NodeMCU with ESP8266
- 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 email@example.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 ;)
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!