Sending Gmail via SMTP with WifiNina

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.

Credited here:
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!

Below is text from the README of my gitlab repo containing all the code.

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:

  1. 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.
    My list:
  1. Gmail preparation:
    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!

  2. Do you understand smtp? If not, read about it here. I cannot explain everything that I hardly understand myself.

  3. Have you cloned the repo yet? If not do it.

  4. 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

  5. Update the email fields appropriately
    the file WiFiSSLClient_gmail_smtp.ino contains a bunch of fields that need updating. They are easily found and updated.

  6. Upload to a Wifi equipped SAMD board (tested on Arduino Wifi 1010) and observe the serial monitor at 115200 Baud.

  7. Type a character and look at the output. It should be similar to that in the file SMTP_Dialogue.h

Good luck!