Introduction

Click image for larger version  Name:	gmail_cover_img.PNG Views:	1 Size:	48.4 KB ID:	591

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.


Things Used In This ProjectPHPoC 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.


Steps
  • Stack PHPoC Shield on Arduino
  • 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
  • Connect LAN cable (or USB Wi-Fi Dongle) to the PHPoC Shield
  • Open GmailClient example via Arduino IDE, goto File -> Examples -> Phpoc -> GmailClient.
  • You will see source code like below

    Code:
    	/* 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() {
    	}
  • Put your Gmail account information (username and password), Upload code to Arduino Uno and see result on "Serial Monitor" of Arduino IDE or "Web Serial Monitor" on Web Browser.
    Click image for larger version  Name:	image_328.jpg Views:	1 Size:	101.1 KB ID:	592
  • If successful, check your email box.


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

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

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