Gmail & Arduino UNO & IPv6

Gmail & Arduino UNO & IPv6 © GPL3+

This example show how to send email via Gmail and ESMTP-based email agent as well from Arduino UNO. It can be used with both IPv4 and IPv6

  • 2,822 views
  • 0 comments
  • 16 respects

Components and supplies

About this project

Most email libraries and examples for Arduino Uno on the internet currently only support to send email via SMTP protocol. That 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 emails via Gmail directly from Arduino Uno. The example is a piece of cake.

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.

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.

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

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/lesssecureapps

In order to use IPv6, just:

  • Adding one more line: Phpoc.beginIP6() in source code;
  • Your LAN network also has to support IPv6.

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

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

Code

IPv4 Source CodeArduino
/* 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() {
}
IPv6 Source CodeArduino
- It's similar to IPv4. Just adding one more line: Phpoc.beginIP6();
- You need to enable IPv6 on PHPoC Shield setting , see this http://www.phpoc.com/support/manual/phpoc_shield_for_arduino/contents.php?id=network_ip_dhcp
- Your LAN network also have to support IPv6
/* 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();
  
  Phpoc.beginIP6();
  
  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() {
}
PHPoC library for Arduino
This library communicates with PHPoC Shield to connect to the Internet. It's also contains Gmail library. How to install library: http://www.phpoc.com/support/manual/phpoc_shield_for_arduino/

Schematics

arduino_shield_conect_SCCdk4scHa.png
Just stack PHPoC Shield on Arduino Uno
Arduino shield conect sccdk4scha

Comments

Similar projects you might like

Arduino, Monitoring Door-Opening via Gmail

Project tutorial by phpoc_man

  • 27,065 views
  • 38 comments
  • 86 respects

Weekly Scheduling with Arduino UNO

by phpoc_man

  • 3,289 views
  • 0 comments
  • 27 respects

Arduino - Detect Someone Taking Your Stuff and send Gmail

Project showcase by IoT_lover

  • 7,828 views
  • 22 comments
  • 24 respects

Nextion LCD communicate with Arduino UNO

by Tamer Savaşcı

  • 23,160 views
  • 4 comments
  • 14 respects
Add projectSign up / Login