1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-13 23:48:46 +01:00
Arduino/libraries/Bridge/examples/Temboo/SendAnEmail/SendAnEmail.ino

138 lines
4.8 KiB
Arduino
Raw Normal View History

2013-06-26 17:29:57 +02:00
/*
SendAnEmail
2014-05-30 12:17:09 +02:00
Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yún.
2013-06-28 11:08:56 +02:00
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
2013-06-26 17:29:57 +02:00
2014-04-03 19:56:46 +02:00
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
2013-06-26 17:29:57 +02:00
http://www.temboo.com
2014-04-03 19:56:46 +02:00
Since this sketch uses Gmail to send the email, you'll also need a valid
Google Gmail account. The sketch needs the username and password you use
2013-07-11 11:24:53 +02:00
to log into your Gmail account - substitute the placeholders below for these values.
2013-06-26 17:29:57 +02:00
2014-05-30 12:17:09 +02:00
This example assumes basic familiarity with Arduino sketches, and that your Yún is connected
2013-06-28 11:08:56 +02:00
to the Internet.
2014-04-03 19:56:46 +02:00
2014-05-30 12:17:09 +02:00
Looking for another API to use with your Arduino Yún? We've got over 100 in our Library!
2013-06-28 11:08:56 +02:00
2013-06-26 17:29:57 +02:00
This example code is in the public domain.
*/
#include <Bridge.h>
2013-07-08 15:09:09 +02:00
#include <Temboo.h>
2013-06-28 11:08:56 +02:00
#include "TembooAccount.h" // contains Temboo account information
2014-04-03 19:56:46 +02:00
// as described in the footer comment below
2013-06-28 11:08:56 +02:00
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
2013-07-03 09:02:59 +02:00
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
2013-07-08 15:09:09 +02:00
// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com"
2013-06-28 11:08:56 +02:00
const String GMAIL_USER_NAME = "xxxxxxxxxx";
// your Gmail password
const String GMAIL_PASSWORD = "xxxxxxxxxx";
// the email address you want to send the email to, eg "jane.doe@temboo.com"
const String TO_EMAIL_ADDRESS = "xxxxxxxxxx";
2013-06-26 17:29:57 +02:00
// a flag to indicate whether we've tried to send the email yet or not
2014-04-03 19:56:46 +02:00
boolean attempted = false;
2013-06-26 17:29:57 +02:00
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
2014-04-03 19:56:46 +02:00
while(!Serial);
2013-06-26 17:29:57 +02:00
Bridge.begin();
}
void loop()
{
// only try to send the email if we haven't already tried
if (!attempted) {
2013-06-26 17:29:57 +02:00
2013-06-28 11:08:56 +02:00
Serial.println("Running SendAnEmail...");
2014-04-03 19:56:46 +02:00
2013-07-08 15:09:09 +02:00
TembooChoreo SendEmailChoreo;
2013-06-26 17:29:57 +02:00
// invoke the Temboo client
2013-07-08 15:09:09 +02:00
// NOTE that the client must be reinvoked, and repopulated with
// appropriate arguments, each time its run() method is called.
SendEmailChoreo.begin();
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// set Temboo account credentials
2013-07-08 15:09:09 +02:00
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
2013-06-26 17:29:57 +02:00
2013-07-03 09:02:59 +02:00
// identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
2013-07-08 15:09:09 +02:00
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
2014-04-03 19:56:46 +02:00
2013-06-26 17:29:57 +02:00
// set the required choreo inputs
2014-04-03 19:56:46 +02:00
// see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
2013-06-26 17:29:57 +02:00
// for complete details about the inputs for this Choreo
2014-04-03 19:56:46 +02:00
// the first input is your Gmail email address.
2013-07-08 15:09:09 +02:00
SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
2013-06-26 17:29:57 +02:00
// next is your Gmail password.
2013-07-08 15:09:09 +02:00
SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
2013-06-28 11:08:56 +02:00
// who to send the email to
2013-07-08 15:09:09 +02:00
SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
2013-06-26 17:29:57 +02:00
// then a subject line
2013-07-08 15:09:09 +02:00
SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature");
2014-04-03 19:56:46 +02:00
// next comes the message body, the main content of the email
2013-07-08 15:09:09 +02:00
SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!");
2013-06-26 17:29:57 +02:00
2014-04-03 19:56:46 +02:00
// tell the Choreo to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
2013-06-26 17:29:57 +02:00
// was able to send our request to the Temboo servers
2013-07-03 09:02:59 +02:00
unsigned int returnCode = SendEmailChoreo.run();
2013-06-26 17:29:57 +02:00
// a return code of zero (0) means everything worked
2013-07-03 09:02:59 +02:00
if (returnCode == 0) {
2014-04-03 19:56:46 +02:00
Serial.println("Success! Email sent!");
2013-06-26 17:29:57 +02:00
} else {
// a non-zero return code means there was an error
// read and print the error message
while (SendEmailChoreo.available()) {
2013-07-03 09:02:59 +02:00
char c = SendEmailChoreo.read();
Serial.print(c);
2013-06-26 17:29:57 +02:00
}
2014-04-03 19:56:46 +02:00
}
2013-06-26 17:29:57 +02:00
SendEmailChoreo.close();
2014-04-03 19:56:46 +02:00
// set the flag showing we've tried
attempted = true;
2013-06-26 17:29:57 +02:00
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
2013-07-03 09:02:59 +02:00
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
2013-06-26 17:29:57 +02:00
2014-04-03 19:56:46 +02:00
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
2013-06-26 17:29:57 +02:00
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
2014-04-03 19:56:46 +02:00
You can find your Temboo App Key information on the Temboo website,
2013-06-28 11:08:56 +02:00
under My Account > Application Keys
2013-06-26 17:29:57 +02:00
2013-07-03 09:02:59 +02:00
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
2014-04-03 19:56:46 +02:00
Keeping your account information in a separate file means you can share the main .ino file without worrying
2013-07-09 20:07:54 +02:00
that you forgot to delete your credentials.
2013-06-26 17:29:57 +02:00
*/