Hardware Required
- Arduino Uno or Mega
- USB Cable for Arduino
- PHPoC Shield (P4S-347) or PHPoC WiFi Shield (P4S-348)
Circuit
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino Uno or Mega
Note that: Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT be used for general I/O.
Install Arduino IDE
If you have not install Arduino IDE yet, please download and install Arduino IDE .
Install Library
- Run Arduino IDE.
- Navigate to Sketch > Include Library > Manage Libraries
- Search "Phpoc" on search bar of the Library Manager.
- Select the PHPoC library and press the [Install] button.
- Restart Arduino IDE for the next step.
Setup Network Information
This part is needed only for the first use.
1. If Ethernet is used
In case of using PHPoC Shield (P4S-348), you have two options to connect to network: Ethernet or WiFi.
If using Ethernet, please follow this instruction to connect the shield to Ethernet.
2. If WiFi is used
WiFi is available in both P4S-347 and P4S-348. Please follow:
- This instruction to access the setup page.
- This instruction if you want to connect shield to WLAN router or Access Point (AP)
- This instruction if you want to operate shield as Access Point (AP)
Source Code
- Open "GmailClient" example on Arduino IDE
Code:// Arduino Email Client - Send Email via Gmail Relay Server // // PHPoC Shield and PHPoC WiFi Shield are Internet Shields for Arduino Uno and // Mega. // // This is an example of using Arduino Uno/Mega and PHPoC [WiFi] Shield to send // an email via Gmail Relay Server. // // Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on // the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT // be used for general I/O. // // This example code was written by Sollae Systems. It is released into the // public domain. // // Tutorial for the example is available here: // https://forum.phpoc.com/articles/tutorials/1238-arduino-gmail-client #include <Phpoc.h> PhpocEmail email; void setup() { Serial.begin(9600); while(!Serial) ; // initialize PHPoC [WiFi] Shield: 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() { }
- The line-by-line explaination of code is presented inside the code.
For more detail of functions's reference, please refer to PHPoC Shield for Arduino Library Reference - Modify source code
Assumption- Sender:
- Name: ABC
- Account: [email protected]
- Password: 1234
- Receiver:
- Name: XYZ
- Account: [email protected]
Note that: receiver can be the same as sender.
Enable "Less secure app access" for the sender account via this link https://www.google.com/settings/security/lesssecureapps
You need to put information of receiver and sender as follows:
- Sender:
- Compile the example code and upload to Arduino by clicking "Upload" button on Arduino IDE
Test and Result
- Open Serial Monitor tool on Arduino IDE to see the output log
- Check your mail box
See Also
- Arduino - TCP Chat Server
- Arduino - TCP IPv6 Chat Server
- Arduino - Telnet Server
- Arduino - SSH Server
- Arduino - SSL Server
- Arduino - Email Client
- Arduino - Gmail Client
- Arduino - Web Client
- Arduino - IPv6 Web Client
- Arduino - SSL Web Client
- Arduino - SSL IPv6 Web Client
- Arduino - Web Server - Remote Push
- Arduino - Web Server - Remote Slide
- Arduino - Web Server - Remote Pad
- Arduino - Web Serial Plotter
- Arduino - Web Serial Monitor
- Arduino - RTC Date and Time
References