|
1 |
| -/* arduino email client - send email via gmail relay server */ |
| 1 | +// Arduino Email Client - Send Email via Gmail Relay Server |
| 2 | +// |
| 3 | +// PHPoC Shield and PHPoC WiFi Shield are Internet Shields for Arduino Uno and |
| 4 | +// Mega. |
| 5 | +// |
| 6 | +// This is an example of using Arduino Uno/Mega and PHPoC [WiFi] Shield to send |
| 7 | +// an email via Gmail Relay Server. |
| 8 | +// |
| 9 | +// Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on |
| 10 | +// the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT |
| 11 | +// be used for general I/O. |
| 12 | +// |
| 13 | +// This example code was written by Sollae Systems. It is released into the |
| 14 | +// public domain. |
| 15 | +// |
| 16 | +// Tutorial for the example is available here: |
| 17 | +// https://forum.phpoc.com/articles/tutorials/1238-arduino-gmail-client |
2 | 18 |
|
3 |
| -#include "SPI.h" |
4 |
| -#include "Phpoc.h" |
| 19 | +#include <Phpoc.h> |
5 | 20 |
|
6 | 21 | PhpocEmail email;
|
7 | 22 |
|
8 | 23 | void setup() {
|
9 | 24 | Serial.begin(9600);
|
10 | 25 | while(!Serial)
|
11 | 26 | ;
|
12 |
| - |
| 27 | + |
| 28 | + // initialize PHPoC [WiFi] Shield: |
13 | 29 | Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
|
14 | 30 | //Phpoc.begin();
|
15 |
| - |
| 31 | + |
16 | 32 | Serial.println("Sending email to gmail relay server");
|
17 | 33 |
|
18 | 34 | // [login using your private password]
|
19 |
| - // Google may block sign-in attempts from some apps or devices that do not use modern security standards. |
| 35 | + // Google may block sign-in attempts from some apps or devices that do not use |
| 36 | + // modern security standards. |
20 | 37 | // Change your settings to allow less secure apps to access your account.
|
21 | 38 | // https://www.google.com/settings/security/lesssecureapps
|
22 |
| - |
| 39 | + |
23 | 40 | // [login using app password]
|
24 | 41 | // 1. turn on 2-step verification
|
25 | 42 | // 2. create app password
|
26 | 43 | // 3. apply app password as your login password
|
27 | 44 |
|
28 |
| - // setup outgoing relay server - gmail.com |
| 45 | + // setup outgoing relay server - gmail.com: |
29 | 46 | email.setOutgoingServer("smtp.gmail.com", 587);
|
30 | 47 | email.setOutgoingLogin("your_login_id", "your_login_password or app_password");
|
31 | 48 |
|
32 |
| - // setup From/To/Subject |
| 49 | + // setup From/To/Subject: |
33 | 50 | email.setFrom("from_email_address", "from_user_name");
|
34 | 51 | email.setTo("to_email_address", "to_user_name");
|
35 | 52 | email.setSubject("Mail from PHPoC Shield for Arduino");
|
36 | 53 |
|
37 |
| - // write email message |
| 54 | + // write email message: |
38 | 55 | email.beginMessage();
|
39 | 56 | email.println("Hello, world!");
|
40 | 57 | email.println("I am PHPoC Shield for Arduino");
|
41 | 58 | email.println("Good bye");
|
42 | 59 | email.endMessage();
|
43 | 60 |
|
44 |
| - // send email |
| 61 | + // send email: |
45 | 62 | if(email.send() > 0)
|
46 | 63 | Serial.println("Email send ok");
|
47 | 64 | else
|
48 | 65 | Serial.println("Email send failed");
|
49 | 66 | }
|
50 | 67 |
|
51 | 68 | void loop() {
|
52 |
| -} |
| 69 | +} |
0 commit comments