Components and supplies
Arduino Yun
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
arduino
1/* 2 SendAnEmail 3 4 Demonstrates sending an email via a Google Gmail account using the Temboo Arduino Yun SDK. 5 6 This example code is in the public domain. 7*/ 8 9#include <Bridge.h> 10#include <Temboo.h> 11#include "TembooAccount.h" // contains Temboo account information 12 13/*** SUBSTITUTE YOUR VALUES BELOW: ***/ 14 15// Note that for additional security and reusability, you could 16// use #define statements to specify these values in a .h file. 17 18// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com" 19const String GMAIL_USER_NAME = "xxxxxxxxxx"; 20 21// your Gmail password 22const String GMAIL_PASSWORD = "xxxxxxxxxx"; 23 24// the email address you want to send the email to, eg "jane.doe@temboo.com" 25const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; 26 27 28boolean success = false; // a flag to indicate whether we've sent the email yet or not 29 30void setup() { 31 Serial.begin(9600); 32 33 // for debugging, wait until a serial console is connected 34 delay(4000); 35 while(!Serial); 36 37 Bridge.begin(); 38} 39 40void loop() 41{ 42 // only try to send the email if we haven't already sent it successfully 43 if (!success) { 44 45 Serial.println("Running SendAnEmail..."); 46 47 TembooChoreo SendEmailChoreo; 48 49 // invoke the Temboo client 50 // NOTE that the client must be reinvoked, and repopulated with 51 // appropriate arguments, each time its run() method is called. 52 SendEmailChoreo.begin(); 53 54 // set Temboo account credentials 55 SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); 56 SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); 57 SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); 58 59 // identify the Temboo Library choreo to run (Google > Gmail > SendEmail) 60 SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); 61 62 63 // set the required choreo inputs 64 // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ 65 // for complete details about the inputs for this Choreo 66 67 // the first input is your Gmail email address 68 SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); 69 // next is your Gmail password. 70 SendEmailChoreo.addInput("Password", GMAIL_PASSWORD); 71 // who to send the email to 72 SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS); 73 // then a subject line 74 SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); 75 76 // next comes the message body, the main content of the email 77 SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); 78 79 // tell the Choreo to run and wait for the results. The 80 // return code (returnCode) will tell us whether the Temboo client 81 // was able to send our request to the Temboo servers 82 unsigned int returnCode = SendEmailChoreo.run(); 83 84 // a return code of zero (0) means everything worked 85 if (returnCode == 0) { 86 Serial.println("Success! Email sent!"); 87 success = true; 88 } else { 89 // a non-zero return code means there was an error 90 // read and print the error message 91 while (SendEmailChoreo.available()) { 92 char c = SendEmailChoreo.read(); 93 Serial.print(c); 94 } 95 } 96 SendEmailChoreo.close(); 97 98 // do nothing for the next 60 seconds 99 delay(60000); 100 } 101}
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
1
0