Introduction: Arduino Uno, Gmail

Most of email library and examples for Arduino Uno on the internet

currently only support to send email via SMTP protocol. It means this library cannot send email through Gmail because Gmail uses ESMTP (Extended SMTP) protocol. In this article, I am going to show you how to send email via Gmail directly from Arduino Uno. The example is a piece of cake.

Step 1: All Things

Components

- Arduino Uno

- PHPoC Shield for Arduino

PHPoC Shield is an internet shield (support both Wi-Fi and Ethernet). It has library to send email via Gmail and other ESMTP-based email agent as well.

All Steps

1. Stack PHPoC Shield on Arduino

2. Install Arduino library and examples for PHPoC Shield:

On Arduino IDE, Go to Sketch -> Include Library -> Manage Libraries. Type “PHPoC” on search box. Click on PHPoC row and click “Install” button.

Or you can get .zip file here: https://github.com/phpoc/arduino

3. Connect LAN cable (or USB Wi-Fi Dongle) to the PHPoC Shield

4. Open GmailClient example via Arduino IDE, goto File -> Examples -> Phpoc -> GmailClient.

You will see source code like below

/* arduino email client - send email via gmail relay server */

#include "SPI.h" #include "Phpoc.h"

PhpocEmail email;

void setup() { Serial.begin(9600); while(!Serial) ; Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP); //Phpoc.begin(); Serial.println("Sending email to gmail relay server");

// [login using your private password] // Google may block sign-in attempts from some apps or devices that do not use modern security standards. // Change your settings to allow less secure apps to access your account. // https://www.google.com/settings/security/lesssecureapps // [login using app password] // 1. turn on 2-step verification // 2. create app password // 3. apply app password as your login password

// setup outgoing relay server - gmail.com email.setOutgoingServer("smtp.gmail.com", 587); email.setOutgoingLogin("your_login_id", "your_login_password or app_password");

// setup From/To/Subject email.setFrom("from_email_address", "from_user_name"); email.setTo("to_email_address", "to_user_name"); email.setSubject("Mail from PHPoC Shield for Arduino");

// write email message email.beginMessage(); email.println("Hello, world!"); email.println("I am PHPoC Shield for Arduino"); email.println("Good bye"); email.endMessage();

// send email if(email.send() > 0) Serial.println("Email send ok"); else Serial.println("Email send failed"); }

void loop() { }

5. Put your Gmail account information (username and password), Upload code to Arduino Uno and see how it work!

Note that: Google may block sign-in attempts from some apps or devices that do not use modern security standards. Change your settings to allow less secure apps to access your account at https://www.google.com/settings/security/lesssecu...

For more information about PHPoC Shield, visit http://www.phpoc.com/phpoc_shield_for_arduino.php... and http://www.phpoc.com/phpoc_shield_for_arduino.php...

If you have any questions or something to discuss, don’t hesitate to leave a comment. I am glad to discuss with you.

Comments

About This Instructable

456views

17favorites

More by phpoc_man:Arduino uno, Weekly SchedulingArduino Uno, GmailArduino, Monitoring Door-Opening Via Gmail
Add instructable to: