Go Down

Topic: How should I get the Arduino to notify Via email or something? (Read 2161 times) previous topic - next topic

samabecker

Okay, I am making a project that should notify me via email or something to tell me when the room gets too hot. Simple eh?
I thought so... But i quickly figured out I can no find a nice way to actually get the Arduino to send an email or something of the sort. . . . . I have an Ethernet Shield so do you guys have any suggestions of what i could do?

zoomkat

Quote
I have an Ethernet Shield so do you guys have any suggestions of what i could do?


You can do a google search of the forum like below and find a lot of previous info on using the arduino for emailing. Using your ISP's smtp server is fairly easy.

http://www.google.com/search?q=email+site%3Ahttp%3A%2F%2Farduino.cc%2Fforum%2Findex.php&hl=en&num=100&lr=&ft=i&cr=&safe=images
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

samabecker

I have done a lot of searching through the forum... All I came up with is that I should try pushing the email to a web server running a PHP script. Would that be the best solution?

zoomkat

Quote
All I came up with is that I should try pushing the email to a web server running a PHP script. Would that be the best solution?


That sounds like some type of klunky workaround. My arduino just sent me an email using the below code setup.

Code: [Select]

/*
SEND AN EMAIL WITH ARDUINO
9/23/11
This code was created by modifying the connect example from arduino.cc and with the help of the YABB forums and their very helpful members.
This code sends an email to any email address and then disconnects. 
*/

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Arduino's artificial mac address
byte ip[] = { 192, 168, 1, 102 }; // my ip
byte server[] = { xxx, yyy, zzz, aaa }; // my smtp.xxx.net server ip

Client client(server, 25);

void setup()
{
  Ethernet.begin(mac, ip);
Serial.begin(9600);

Serial.println("connecting...");

if (client.connect()) {
                        Serial.println("connected");
   
                        client.println("HELO itismeletschat"); /* say hello (statement after helo is needed but irrelevant)*/

                        client.println("MAIL From: me@my-isp.net"); /* identify sender, this should be the same as the smtp server you are using */

                        client.println("RCPT To: you@your-isp.net"); /* identify recipient */

                        client.println("DATA");

                        client.println("To: you@your-isp.net"); /* identify recipient */
                        client.println("Subject: You Have Arduino Mail!!"); /* insert subject */

                        client.println("Please let me know it worked!!!"); /* insert body */
                        client.println("."); /* end email */
                 
                        client.println("QUIT"); /* terminate connection */
                       
                        client.println();
   
} else {
   Serial.println("connection failed");
}
}

void loop()
{
   delay(10000);
   if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   for(;;)
     ;
}
}
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

samabecker

thanks for the code! but, how exactly does that handle authentication?

and i'm assuming it also wouldn't be able to use something like Gmail SMTP.

zoomkat

Below is some previously posted code with provisions for user name and password. You may want to do a google advanced search of the forum for pevious post concerning using the gmail servers.

Code: [Select]

//http://www.motobit.com/util/base64-decoder-encoder.asp e
//http://webnet77.com/cgi-bin/helpers/base-64.pl


#include <SPI.h>
#include <Ethernet.h>

// Local network configuration:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x23, 0x5D };
byte ip[] = { 192,168,0, 177 };

// Login data:
String UserName64 = "XXXXXXX";
String Password64 = "XXXXXXX";

// SMTP server data:
// smtp.libero.it : 212.52.84.54
// smtp.iol.it : 212.52.84.203
// out.virgilio.it : 62.211.72.20
byte server[] = { 212, 52, 84, 54 }; // SMTP server
String ServerName = "libero.it";

// Mail data:
String Sender = "XXXXXXX@libero.it";
String Recipient = "XXXXXXX@libero.it";
String Subject = "Messaggio inviato da Arduino!";
String Body = "Testo del messaggio\nsu piu'\ndi una riga.";

int time = 1000;
int wait = 1000;
String ServerResponse="";
Client client(server, 25);

void setup()
{
  Serial.begin(9600);
  Serial.println("Program started, waiting for router...");
  delay(time); /* allow the router to identify the Arduino before the Arduino connects to the internet */

  Serial.println("Starting network module...");
  Ethernet.begin(mac, ip);
  delay(2000);

  Serial.println("connecting...");
  if (client.connect()) {
     Serial.println("connected");

     SendMsg("EHLO " + ServerName); /* say hello*/
     SendMsg("AUTH LOGIN ");
     SendMsg(UserName64); /* Username*/
     SendMsg(Password64); /* Password */
     SendMsg("MAIL From:<" + Sender +">"); /* identify sender */
     SendMsg("RCPT To:<" + Recipient + ">"); /* identify recipient */
     SendMsg("DATA");
     SendMsg("To: " + Recipient); /*  recipient in message header */
     SendMsg("From: " + Sender); /* seder name in message header */
     SendMsg("Subject: "+ Subject); /* insert subject */
     SendMsg(""); /* empty line */
     SendMsg(Body); /* insert body */
     SendMsg(""); /* empty line */
     SendMsg("."); /* end mail */
     SendMsg("QUIT"); /* terminate connection */
     client.println();

  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

void GetResponse() {
    if (client.available()) {
         char c = client.read();
         while (client.available()) { // Store command char by char.
           ServerResponse +=c;
           c = client.read();
         }
    Serial.println("<<<" + ServerResponse);
    ServerResponse="";
  }
}

void SendMsg(String m) {
   client.println(m);
   Serial.println(">>>" + m);
   delay(wait); /* wait for a response */
   GetResponse();
}
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

samabecker

Thanks a bunch! Especially for the quick reply haha.
I'll give it a go when I get home.

pittom

what mail are you using? i tried gmail and gmx mail(gmx workes on my security cam)but can't get any to work.

samabecker

#8
Sep 26, 2011, 01:48 am Last Edit: Sep 26, 2011, 01:54 am by samabecker Reason: 1
Okay I (sorta) got this working right. I am using a private/work SMTP server and it usually connects fine over the internet but when i try reconnecting with the same LOCAL IP address it wont connect but if i change it, it does. THIS MAKES noooo sense to me what-so-ever...like, I can connect perfectly fine one time and then hit the reset button and it wont connect... ): please help me. When i use cmd to telnet in, it works every time. but my little arduino seems to be having issues :/

Jack Christensen

How about an SMS message? There are at least a few ways to send Tweets from an Arduino with an Ethernet shield (GIYF). Twitter can then send them to your phone. I'm using ThingSpeak and their Twitter interface to do something similar.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

samabecker

Yeah. but.. Now with twitter using Oauth, it's pretty much you passing your log in info and status to a server which then does the real work of posting the twitter status. Which is what i described up there... Which i'd rather not do, i mean i've got the thing to send multiple emails and it worked great! just for some reason it wont simply connect : / maybe i can try again when i'm at the office on the same local network as the SMTP server, perhaps that will stop my issue.

samabecker

Update** Okay, I used this code on the same local network as the mail server and it worked out perfectly fine and connected like a charm. :DD thanks everyone for the help!

Pauly

To get around the Twitter authentication I tried a different service called Notifio.
Sends text messages to my phone.  Works great.

http://notifo.com/

Go Up