Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  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 <TembooYunShield.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"
  19. const String GMAIL_USER_NAME = "";
  20.  
  21. // your Gmail password
  22. const String GMAIL_PASSWORD = "";
  23.  
  24. // the email address you want to send the email to, eg "jane.doe@temboo.com"
  25. const String TO_EMAIL_ADDRESS = "";
  26.  
  27. boolean success = false; // a flag to indicate whether we've sent the email yet or not
  28.  
  29. void setup() {
  30. Serial.begin(9600);
  31.  
  32. // for debugging, wait until a serial console is connected
  33. delay(4000);
  34. while(!Serial);
  35.  
  36. Bridge.begin();
  37. }
  38.  
  39. void loop()
  40. {
  41. // only try to send the email if we haven't already sent it successfully
  42. if (!success) {
  43.  
  44. Serial.println("Running SendAnEmail...");
  45.  
  46. TembooYunShieldChoreo SendEmailChoreo;
  47.  
  48. // invoke the Temboo client
  49. // NOTE that the client must be reinvoked, and repopulated with
  50. // appropriate arguments, each time its run() method is called.
  51. SendEmailChoreo.begin();
  52.  
  53. // set Temboo account credentials
  54. SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
  55. SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  56. SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
  57.  
  58. // identify the Temboo Library choreo to run (Google > Gmail > SendEmail)
  59. SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
  60.  
  61. // set the required choreo inputs
  62. // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/
  63. // for complete details about the inputs for this Choreo
  64.  
  65. // the first input is your Gmail email address
  66. SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
  67. // next is your Gmail password.
  68. SendEmailChoreo.addInput("Password", GMAIL_PASSWORD);
  69. // who to send the email to
  70. SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
  71. // then a subject line
  72. SendEmailChoreo.addInput("Subject", "Arduino Email");
  73.  
  74. // next comes the message body, the main content of the email
  75. SendEmailChoreo.addInput("MessageBody", "This is a test.");
  76.  
  77. // tell the Choreo to run and wait for the results. The
  78. // return code (returnCode) will tell us whether the Temboo client
  79. // was able to send our request to the Temboo servers
  80. unsigned int returnCode = SendEmailChoreo.run();
  81.  
  82. // a return code of zero (0) means everything worked
  83. if (returnCode == 0) {
  84. Serial.println("Success! Email sent!");
  85. success = true;
  86. } else {
  87. // a non-zero return code means there was an error
  88. // read and print the error message
  89. while (SendEmailChoreo.available()) {
  90. char c = SendEmailChoreo.read();
  91. Serial.print(c);
  92. }
  93. }
  94. SendEmailChoreo.close();
  95.  
  96. // do nothing for the next 60 seconds
  97. delay(60000);
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement