source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 6.0 KB
Line 
1/*
2  SendAnEmail
3
4  Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yún.
5
6  Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
7
8  A Temboo account and application key are necessary to run all Temboo examples.
9  If you don't already have one, you can register for a free Temboo account at
10  http://www.temboo.com
11
12 Instructions:
13 
14  1. Create a Temboo account: http://www.temboo.com
15 
16  2. Retrieve your Temboo application details: http://www.temboo.com/account/applications
17 
18  3. Replace the values in the TembooAccount.h tab with your Temboo application details
19 
20  4. You'll also need a Gmail account. Update the placeholder Gmail address in the code
21     below with your own details.
22     
23     https://www.gmail.com
24 
25  5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific
26     password to allow Temboo to access your Google account: https://www.google.com/landing/2step/.
27     
28  6. After you've enabled 2-Step authentication, you'll need to create an App Password:
29     https://security.google.com/settings/security/apppasswords
30 
31  7. In the "Select app" dropdown menu, choose "Other", and give your app a name (e.g., TembooApp).
32 
33  8. Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo.
34 
35  9. Copy and paste this password into the code below, updating the GMAIL_APP_PASSWORD variable
36 
37  10. Upload the sketch to your Arduino Yún and open Arduino's serial monitor
38 
39  NOTE: You can test this Choreo and find the latest instructions on our website:
40  https://temboo.com/library/Library/Google/Gmail/SendEmail
41 
42  You can also find an in-depth version of this example here:
43  https://temboo.com/hardware/ti/send-an-email
44
45  This example assumes basic familiarity with Arduino sketches, and that your Yún is connected
46  to the Internet.
47 
48  Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
49
50  This example code is in the public domain.
51*/
52
53#include <Bridge.h>
54#include <Temboo.h>
55#include "TembooAccount.h" // contains Temboo account information
56                           // as described in the footer comment below
57
58/*** SUBSTITUTE YOUR VALUES BELOW: ***/
59
60// Note that for additional security and reusability, you could
61// use #define statements to specify these values in a .h file.
62
63// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com"
64const String GMAIL_USER_NAME = "xxxxxxxxxx";
65
66// your application specific password (see instructions above)
67const String GMAIL_APP_PASSWORD = "xxxxxxxxxx";
68
69// the email address you want to send the email to, eg "jane.doe@temboo.com"
70const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
71
72// a flag to indicate whether we've tried to send the email yet or not
73boolean attempted = false;
74
75void setup() {
76  Serial.begin(9600);
77
78  // for debugging, wait until a serial console is connected
79  delay(4000);
80  while(!Serial);
81
82  Bridge.begin();
83}
84
85void loop()
86{
87  // only try to send the email if we haven't already tried
88  if (!attempted) {
89
90    Serial.println("Running SendAnEmail...");
91 
92    TembooChoreo SendEmailChoreo;
93
94    // invoke the Temboo client
95    // NOTE that the client must be reinvoked, and repopulated with
96    // appropriate arguments, each time its run() method is called.
97    SendEmailChoreo.begin();
98   
99    // set Temboo account credentials
100    SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
101    SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
102    SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
103
104    // identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
105    SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
106 
107
108    // set the required choreo inputs
109    // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
110    // for complete details about the inputs for this Choreo
111
112    // the first input is your Gmail email address.     
113    SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
114    // next is your application specific password
115    SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD);
116    // who to send the email to
117    SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
118    // then a subject line
119    SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
120
121     // next comes the message body, the main content of the email   
122    SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
123
124    // tell the Choreo to run and wait for the results. The
125    // return code (returnCode) will tell us whether the Temboo client
126    // was able to send our request to the Temboo servers
127    unsigned int returnCode = SendEmailChoreo.run();
128
129    // a return code of zero (0) means everything worked
130    if (returnCode == 0) {
131        Serial.println("Success! Email sent!");
132    } else {
133      // a non-zero return code means there was an error
134      // read and print the error message
135      while (SendEmailChoreo.available()) {
136        char c = SendEmailChoreo.read();
137        Serial.print(c);
138      }
139    }
140    SendEmailChoreo.close();
141   
142    // set the flag showing we've tried
143    attempted = true;
144  }
145}
146
147/*
148  IMPORTANT NOTE: TembooAccount.h:
149
150  TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
151  You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
152  by inserting your own Temboo account name and app key information. The contents of the file should
153  look like:
154
155  #define TEMBOO_ACCOUNT "myTembooAccountName"  // your Temboo account name
156  #define TEMBOO_APP_KEY_NAME "myFirstApp"  // your Temboo app key name
157  #define TEMBOO_APP_KEY  "xxx-xxx-xxx-xx-xxx"  // your Temboo app key
158
159  You can find your Temboo App Key information on the Temboo website,
160  under My Account > Application Keys
161
162  The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
163
164  Keeping your account information in a separate file means you can share the main .ino file without worrying
165  that you forgot to delete your credentials.
166*/
Note: See TracBrowser for help on using the repository browser.