How can we connect to the gmail smtp server and send an email using the WifiNina library?
The answer is not as hard as one might expect, given the amount of people who asked this and never got a reply.
Arturo Guadalupi for his Base64 library which I updated: GitHub - agdl/Base64: A Base64 library for Arduino
Ralph Bacon for providing the basic file structure GitHub - RalphBacon/Secure-Gmail: Send Gmail securely (encrypted) from your Arduino, ESP8266 or other microcontroller
www.samlogic.net for providng smtp reference documentation: SMTP Commands Reference (covers HELO/EHLO, MAIL, RCPT, DATA, RSET, VRFY, AUTH, STARTTLS etc)
I give my most sincere credit and respect to all the Arduino creators and the great community around it!
All my work was done on an Arduino Wifi 1010, but I assume it will work on any of the SAMD based Arduino boards.
Here's how I did it:
- Arduino Preparation:
use the WifiNina firmware and certificate updater to update your firmware.
use the lower part of the firmware tool window to update your certificates; be sure that google.com:443 is in the list.
find the gmail security settings page: https://myaccount.google.com/security
enable 2 factor identification
create an app password for this application. The password is a 16 character string, copy it and keep it handy!
Do you understand smtp? If not, read about it here. I cannot explain everything that I hardly understand myself.
Have you cloned the repo yet? If not do it.
Update the file arduino_secrets.h with
your wifi network SSID
your wifi network PASWWORD
your gmail account
your gmail account app specific password that we got in step 2. above
Update the email fields appropriately
WiFiSSLClient_gmail_smtp.inocontains a bunch of fields that need updating. They are easily found and updated.
Upload to a Wifi equipped SAMD board (tested on Arduino Wifi 1010) and observe the serial monitor at 115200 Baud.
Type a character and look at the output. It should be similar to that in the file