Advertisement
snargledorf

Email multiple email addresses from file with Arduino

Oct 13th, 2011
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. void sendEmails(char* message) {
  2.     byte server[] = { 209, 225, 8, 76 }; // Your SMTP server ip goes here
  3.     Client client (server, 25);
  4.     File file = SD.open(FILE_WITH_EMAILS_GOES_HERE);
  5.     if (file) {
  6.         int fileSize = file.size();
  7.         char recipientName[50];
  8.         memset(recipientName, '\0', 50);
  9.         byte p = 0;
  10.         Serial.println("waiting for connection....");
  11.         do {
  12.             client.connect();
  13.             delay(1000);
  14.         } while (!client.connected());
  15.         if (client.connected()) {
  16.             Serial.println("Connected!");
  17.             for (int i = 0; i < fileSize; i++) {
  18.                 byte c = file.read();
  19.                 if (c == '\n') {
  20.                     p = 0;
  21.                     client.println("HELO domain.com");
  22.                     delay(500);
  23.                     client.println("MAIL FROM: name@domain.com");
  24.                     delay(500);
  25.                     char rcptLine[60] = "RCPT To: <";
  26.                     strcat(rcptLine, recipientName);
  27.                     strcat(rcptLine, ">\r\n");
  28.                     client.write(rcptLine);
  29.                     delay(500);
  30.                     client.println("DATA");
  31.                     delay(500);
  32.                     client.println("Subject: READ ME!");
  33.                     delay(500);
  34.                     client.println(message);
  35.                     delay(500);
  36.                     client.println(".");
  37.                     delay(500);
  38.                 } else {
  39.                     recipientName[p] = c;
  40.                     p++;
  41.                 }
  42.             }
  43.             client.println("QUIT");
  44.             client.stop();
  45.         }
  46.         file.close();
  47.     } else {
  48.         Serial.println("File couldn't be opened");
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement