Arduino - Gmail
In this guide, we will learn how to set up the Arduino to send an email using your Gmail account. The email will be sent from a Gmail account and can be received by any email account.
Hardware Required
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Pre-Preparation
To use the code, we need a Gmail account and a special password for the app. Here are the important details to remember:
- Please make a new Gmail account just for testing, not your usual one, to prevent problems.
- The password in the Arduino code is different from your Gmail login password. You must get an "App Password" from your Google Account by following specific steps.
Here are the steps one by one:
- Make a new Gmail account.
- Sign into the account you just made.
- Visit your Google Account.
- Go to the "Security" section.
- Turn on 2-Step Verification (You must activate 2-Step Verification to use app passwords).
- Go to the Google App Passwords website and make an app password. You can choose any name for it.
- Press the Create button. You will get a 16-digit password that appears like this:
- Keep and save this 16-digit number. You will use it in the Arduino code in the next step.
※ NOTE THAT:
Google's user interface might change. If you can't find "App Passwords" by following the steps above, search for "How to get Google App Passwords" to find updated instructions.
Arduino Code
Quick Steps
- If this is the first time you use Arduino Uno R4, see how to setup environment for Arduino Uno R4 on Arduino IDE.
- Connect the Arduino board to your PC using a USB cable.
- Open the Arduino IDE on your PC.
- Select the right Arduino board (Arduino Uno R4 WiFi) and COM port.
- Open the Library Manager by clicking on the Library Manager icon on the left side of the Arduino IDE.
- Search for ESP Mail Client and find the ESP Mail Client by Mobizt.
- Click the Install button to install the ESP Mail Client library.
- Copy the code above and open it in the Arduino IDE.
- Update your WiFi details by replacing WIFI_SSID and WIFI_PASSWORD with your WiFi network's SSID and password.
- Edit your email details in the code by entering your email and password in SENDER_EMAIL and SENDER_PASSWORD.
- Change the email address for receiving messages to your email by updating RECIPIENT_EMAIL. Note: the recipient email may be the same as the sender's email.
※ NOTE THAT:
- The email of the sender must be a Gmail account.
- The password for the sender is the App password you received in the previous step.
- The recipient's email can be of any type.
- Click the Upload button in Arduino IDE to send code to Arduino.
- Open the Serial Monitor.
- Look at the result on Serial Monitor.
- Check the email inbox of the person you sent the email to. You will receive an email like the following:
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.