email using arduino (plus a bit on home automation)

I've looked at the Arduino "wifi email client" and "email client" pages. They seem to be able to send an email at a server such as "mail.yourmailserver.com", but can you send an email to an address such as "me12345@yahoo.com" this way?

I send email to my gmail account this way. I can send text messages to my Verizon cellphone. The code I use sends email like an email server sends email to another email server (called a relay). http://playground.arduino.cc/Code/Email

It depends on your public ip. I have a commercial account, so I can send that way. If you have a residential account (dhcp issued ip) then you might be blocked.

Sometimes, you can use your ISP's email server as a relay for your Arduino if the security is not TLS or SSL.

edit: If you want to send email to a yahoo account, you must use the email server that services the yahoo accounts. Currently, they are

C:\Documents and Settings\user>nslookup Default Server: ip68-105-28-16.at.at.cox.net Address: 68.105.28.16

set query=mx yahoo.com Server: ip68-105-28-16.at.at.cox.net Address: 68.105.28.16

Non-authoritative answer: yahoo.com MX preference = 1, mail exchanger = mta6.am0.yahoodns.net yahoo.com MX preference = 1, mail exchanger = mta7.am0.yahoodns.net yahoo.com MX preference = 1, mail exchanger = mta5.am0.yahoodns.net

yahoo.com nameserver = ns5.yahoo.com yahoo.com nameserver = ns6.yahoo.com yahoo.com nameserver = ns8.yahoo.com yahoo.com nameserver = ns1.yahoo.com yahoo.com nameserver = ns2.yahoo.com yahoo.com nameserver = ns3.yahoo.com yahoo.com nameserver = ns4.yahoo.com mta5.am0.yahoodns.net internet address = 98.138.112.37 mta5.am0.yahoodns.net internet address = 63.250.192.45 mta5.am0.yahoodns.net internet address = 66.196.118.33 mta5.am0.yahoodns.net internet address = 66.196.118.240 mta5.am0.yahoodns.net internet address = 98.136.217.202 mta5.am0.yahoodns.net internet address = 98.136.217.203 mta5.am0.yahoodns.net internet address = 98.138.112.33 mta5.am0.yahoodns.net internet address = 98.138.112.34 mta6.am0.yahoodns.net internet address = 66.196.118.35 mta6.am0.yahoodns.net internet address = 66.196.118.37 mta6.am0.yahoodns.net internet address = 66.196.118.240 mta6.am0.yahoodns.net internet address = 98.136.217.202 mta6.am0.yahoodns.net internet address = 98.138.112.35 mta6.am0.yahoodns.net internet address = 98.138.112.37 mta6.am0.yahoodns.net internet address = 66.196.118.33 mta6.am0.yahoodns.net internet address = 66.196.118.34

I’ll start trying things. To be more specific, at home I have

internet <==> charter cable <==> router <==> RNXV <==> Arduino

as well as

internet <==> charter cable <==> router <==> ethernet shield <==> Arduino

I want to be able to send emails from my Arduino to my email acct at yahoo.com,
for example to < me12345@yahoo.com >.

Using my code above…

// change these
char server[] = "email.yourdomain.com";
client.println(F("helo 1.2.3.4"));
client.println(F("RCPT To: <you@yourdomain.com>"));
client.println(F("To: You <you@yourdomain.com>"));

// to these
char server[] = "mta6.am0.yahoodns.net";
client.println(F("helo 1.2.3.4")); // this should be your public ip
client.println(F("RCPT To: <me12345@yahoo.com>"));
client.println(F("To: Me <me12345@yahoo.com>"));

You’ll need to change the from addresses also. The sender domain must resolve or it will be rejected. I checked this with my yahoo account.

edit: Mine ended up in my spam folder.

HI,

I am trying to do the similar thing. But I am getting the following error

Ready. Press 'e' to send.
connected

Timeout
Email failed

Can anyone please help me with that.

Thank you

It connected to the server, but the email server did not send a hello message. That would happen if it is not an email server. What server are you using?

edit: This also happens if it is an email server designed to accept email from client applications (Outlook or Thunderbird) on a secure port, like 465 or 587. Those ports normally require TLS, and the ethernet library does not support that.

You need to find the server that handles email for that domain on port 25. I use nslookup for that.

nslookup
set query=mx
mydomain.com

oric_dan:
I want to be able to send emails from my Arduino to my email acct at yahoo.com,
for example to < me12345@yahoo.com >.

With RFX:duino, the sketch running on my swimming pool monitor/controller does it like so:

  int ack = rfx.alert_start_request(ALERT_EMAIL,5000);
  if (ack) {
    rfx.prln("You are out of Chlorine");
    rfx.prln("\n(Sent from your swimming pool.)\n");
  }
  ack = rfx.alert_stop_request(5000); // this says ready to receive normal stream

The email message is passed to a pre-configured email server on the gateway, and you get an email:

From: yourswimmingpool@yahoo.com
Subject: RFX Alert 

You are out of Chlorine

(Sent from your swimming pool.)

One of the nice things about setting things up this way is that the RFX gateway server, being Linux based, has no problem connecting using TLS (or anything else involving secure sockets.) So all this stuff becomes very easy.

Also, the programming on the Arduino side of things becomes pretty simple too, obviously.

Finally, the method is easy to generalize, so I have alerts configured for sending an SMS via a POST method to a service provider, a tweet to twitter, and sending a data update to Xively via a PUT method.

  int ack = rfx.alert_start_request(ALERT_SMS,5000);
  if (ack) {
    rfx.prln("You are out of Chlorine");
  }
  ack = rfx.alert_stop_request(5000); // this says ready to receive normal stream

etc.

Thought you might find this interesting! (You’ve got me thinking I’ll have to get some more documentation put up on this on the website, maybe some simple example sketches…)

I haven't had a chance to wring out the email problem as yet [been doing xiveling, tweeting, RFM12ing, ColorLCDing, on and on, lately], and am currently sending specific "alarm/error" messages to a Twitter account, and regular data logging to xively, via the Ethernet shield stacked on my Arduino board. This Arduino also talks to multiple RFM12 nodes [more than 1, some day], analyzes the info, and passes out to my router via the Ethernet board.

What exactly do you mean by "email message is passed to a pre-configured email server on the gateway"? So, it's running on your custom server, not the Arduino?

Thank you guys for your reply. I used to nslookup to find the server name. I used this for gmail gmail-smtp-in.l.google.com for yahoo i used this one mta5.am0.yahoodns.net I am using 25 port. Thank you

@husnalraikumar, thanks for the update, so are you getting it to work now? I'm still very green at this stuff. I tried some things a couple of weeks ago, which didn't work, and was kind of discouraged from Tim's comment "edit: Mine ended up in my spam folder". I thought - it doesn't work for him either, so ????

Sorry about that. I wasnt clear. It is still showing me the same message

Time Out

@oric-dan: Mine worked fine. My gmail and yahoo accounts both received the email. It was accepted and interpreted as spam, and put in my spam folder in both accounts until I told my accounts it was not spam. Now it shows up like all the rest.

BTW, Yahoo would not show my messages in the email with my old playground code. It needed a blank line between the header and the body of the email. It now reflects that change.

@husnalraikumar: Let me check the playground code again. It worked the other day when I checked both Yahoo and Gmail. Check back in a while.

edit: I checked Gmail and it worked fine, except, once again, it is in my spam folder at Gmail.

oric_dan: I haven't had a chance to wring out the email problem as yet [been doing xiveling, tweeting, RFM12ing, ColorLCDing, on and on, lately], and am currently sending specific "alarm/error" messages to a Twitter account, and regular data logging to xively, via the Ethernet shield stacked on my Arduino board. This Arduino also talks to multiple RFM12 nodes [more than 1, some day], analyzes the info, and passes out to my router via the Ethernet board.

Sounds busy!

oric_dan: What exactly do you mean by "email message is passed to a pre-configured email server on the gateway"? So, it's running on your custom server, not the Arduino?

The RFX gateway server is a embedded Linux box (Raspberry Pi) that brokers all the Internet connections for its clients (the nRF24L01+ connected Arduinos.) When it get's an "alert_start_request" message from one of the clients (see my example Arduino code snippet above), it will send an ack back to indicate it is ready to receive the alert message, and will handle forwarding the message to the requested alert service (email, SMS, twitter, etc.) It knows when you have ended the alert message because you send it the "alert_stop_request" message.

What that "handling" actually entails in terms of (say) an email alert is configured on the RFX gateway server, so a configuration file for that type of alert specifies the email will be sent to such-and-such address, from such-and-such a sender, with such-and-such a subject, etc. (You set up the parameters in advance, so it is "pre-configured" in that sense.)

The main RFX gateway program offloads the task to an alert server program for that service (all still running on the RPi), and it will manage the SMTP transaction (or whatever is required) in the background.

Does that make sense?

It just seemed to make things simpler to do things this way, and overall made a lot more sense, rather than have the Arduinos fiddling around managing the SMTP details themselves. (And, of course, there are some things they just can't do, like anything involving SSL.)

I checked the playground code, changing only what is specified. Gmail sent ok. Yahoo sent ok. Both using the servers you specified.

edit: Here is a transaction. I changed the email addresses.

Ready. Press ‘e’ to send.
connected
220 mta1120.mail.gq1.yahoo.com ESMTP YSmtpProxy service ready
Sending helo
250 mta1120.mail.gq1.yahoo.com
Sending From
250 sender SurferTim@gmail.com ok
Sending To
250 recipient surfertim@yahoo.com ok
Sending DATA
354 go ahead
Sending email
250 ok dirdel
Sending QUIT
221 mta1120.mail.gq1.yahoo.com
disconnected
Email sent

Thank you SurfTim for checking the code. I tried it again but it is still showing me the same message. I am making all the changes as stated in the code.(Mac, Ip, subnet, gateway, public ip, email server, email addresses) my ethernet shield is connected with a cisco DPC3825 modem, Do you think it has to be with the type of modem i am using ?

Thank you

pico:

oric_dan:
I haven’t had a chance to wring out the email problem as yet [been doing xiveling, tweeting, RFM12ing, ColorLCDing, on and on, lately], and am currently sending specific “alarm/error” messages to a Twitter account, and regular data logging to xively, via the Ethernet shield stacked on my Arduino board. This Arduino also talks to multiple RFM12 nodes [more than 1, some day], analyzes the info, and passes out to my router via the Ethernet board.

Sounds busy!

oric_dan:
What exactly do you mean by “email message is passed to a pre-configured email server on the gateway”? So, it’s running on your custom server, not the Arduino?

The RFX gateway server is a embedded Linux box (Raspberry Pi) that brokers all the Internet connections for its clients (the nRF24L01+ connected Arduinos.)

Thanks for the rundown, pico. Right, the rPi is the brains of the outfit. There is definitely some advantage to buying/using an off-the-self solution.

Since starting this thread, I’ve gotten the things mentioned above to work, but hadn’t yet gone back to trying the email business again. In my case, it’s all Arduino → ColorLCD [menuing system] on top of Proto shield with RFM12/etc, on top of Ethernet shield, on top of ATmega1284 board.

And of course, Ethernet, SD card, ColorLCD, and RFM12 are all SPI devices. The trick is to fix the libraries so all the SPI devices play well together. Most SPI libraries seem to want to use the same CS/etc pins. Almost there. Down to getting the 1284 to talk properly to the RFM12 [the library has the usual problems].

So, it’s nice your rPi is doing all the heavy-lifting, but won’t help too much here, thanks ;-). I guess I’ll figure out the limitations of the Arduino as I go along - SSL, whatever. With xively and tweeting already operational, it’ll certainly do most of what I want to do, in any case.

SurferTim:
I checked the playground code, changing only what is specified. Gmail sent ok. Yahoo sent ok. Both using the servers you specified.

edit: Here is a transaction. I changed the email addresses.

Ready. Press ‘e’ to send.
connected
220 mta1120.mail.gq1.yahoo.com ESMTP YSmtpProxy service ready
Sending helo
250 mta1120.mail.gq1.yahoo.com
Sending From
250 sender SurferTim@gmail.com ok
Sending To
250 recipient surfertim@yahoo.com ok
Sending DATA
354 go ahead
Sending email
250 ok dirdel
Sending QUIT
221 mta1120.mail.gq1.yahoo.com
disconnected
Email sent

Thanks for the new input, Tim. I’ll try the email stuff again after my head stops spinning from all the other things being juggled around here, LOL.

oric_dan:

pico:

oric_dan: I haven't had a chance to wring out the email problem as yet [been doing xiveling, tweeting, RFM12ing, ColorLCDing, on and on, lately], and am currently sending specific "alarm/error" messages to a Twitter account, and regular data logging to xively, via the Ethernet shield stacked on my Arduino board. This Arduino also talks to multiple RFM12 nodes [more than 1, some day], analyzes the info, and passes out to my router via the Ethernet board.

Sounds busy!

oric_dan: What exactly do you mean by "email message is passed to a pre-configured email server on the gateway"? So, it's running on your custom server, not the Arduino?

The RFX gateway server is a embedded Linux box (Raspberry Pi) that brokers all the Internet connections for its clients (the nRF24L01+ connected Arduinos.) .........

Thanks for the rundown, pico. Right, the rPi is the brains of the outfit. There is definitely some advantage to buying/using an off-the-self solution.

Since starting this thread, I've gotten the things mentioned above to work, but hadn't yet gone back to trying the email business again. In my case, it's all Arduino --> ColorLCD [menuing system] on top of Proto shield with RFM12/etc, on top of Ethernet shield, on top of ATmega1284 board.

And of course, Ethernet, SD card, ColorLCD, and RFM12 are all SPI devices. The trick is to fix the libraries so all the SPI devices play well together. Most SPI libraries seem to want to use the same CS/etc pins.

The other two things that make sharing a SPI bus amongst devices is when they disagree over SPI mode (most devices seem to be mode 0 or 1, but occasionally, you get oddballs doing 2 or 3.)

Then there's max speed, of course. Usually the max speed of SPI slave is faster than a 16MHz Arduino can put out though.

oric_dan: Almost there. Down to getting the 1284 to talk properly to the RFM12 [the library has the usual problems].

BTW, what are the RFM12 modules actually communicating, just out of interest? (Sorry if you've already discussed this in other threads.)

oric_dan: So, it's nice your rPi is doing all the heavy-lifting, but won't help too much here, thanks ;-). I guess I'll figure out the limitations of the Arduino as I go along - SSL, whatever. With xively and tweeting already operational, it'll certainly do most of what I want to do, in any case.

The lack of SSL is really only an issue when you get some server that insists on using https or a mail server that will only accept secure connections, but unfortunately that seems to be getting increasingly commonplace. I remember trying to find a SMS gateway service that didn't insist on a https connection to their API before I was using the Linux gateway to do the "heavy lifting", as you say... I eventually found one, but what a pain.

But now I send my emails with three lines of code in my sketches, and do Xively updates with four. If an Arduino needs the time of day, (e.g., for an Xively update), don't even need an RTC -- just ask the gateway to return the output of the Linux "date" command.

I really don't miss the Ethernet shield at all!

Anyway, thought you might find the Arduino + Linux gateway approach interesting for doing things like email. It seems to me a natural "horses for courses" thing.

If you've already got a thread where you describe your project in detail, just provide a pointer rather than repeating yourself just for my benefit.

pico, thanks for the additional info about SSL, email, etc.

I don’t recall describing my system in any great detail elsewhere [but I’m pretty muddled lately, LOL]. Basically, a standalone home automation system, that won’t require a PC to be turned on. Base station, plus a remote node in each room of the home.

Since I can pickup 30 routers here, I decided to go with RFM12s at 433 Mhz. I found they will transmit about 40m [120 feet] with 1mW output power.

Base station - 4 board stack:

  • ColorLCD shield - menuing.
  • proto board with RFM12, plus misc leds, I/O.
  • ethernet shield
  • ATmega1284 board - personal design.

Remote nodes:

  • typically ATmega 328 boards with RFM12.
  • misc monitoring, inc PIR, temperatures, Vin, etc, plus 1-2 digital outputs.

Basic menu, shown below on a Mega board.

At this point, I’m down to getting the RFM12 to work with the ATmega1284, and everything else is about done. There is precious little direct library support for the 1284, so I’ve needed to hack most of the libraries.

ami-menu1.jpg

oric_dan: - ATmega1284 board - personal design.

Would that be the OT-TREDICI? (Just found your website!)

oric_dan: Basic menu, shown below on a Mega board.

Boo, I was hoping you'd show a pic of your board! Menu looks good, though.

oric_dan: At this point, I'm down to getting the RFM12 to work with the ATmega1284, and everything else is about done. There is precious little direct library support for the 1284, so I've needed to hack most of the libraries.

I very much like the fact that you've kept with the PDIP package for your kit design, I think that keeps these hobby project boards much more in the spirit of the original Arduino projects. (I've tried to do the same thing with the minimalist nRF24L01+ enabled 328p dev board kit I'm selling... all through hole components, even with big ol' TO-220 voltage regulator packages, just to keep it all accessible for people without SMD skills, equipment, and eyesight.)

The 644 family (including the 1284) provide a great basis for a "beefier" Arduino... I wish Arduino had gone with the PDIP designs for some versions of their "Mega" boards, just so it was all better supported out of the box. I actually think the 644 and friends are preferable to the ARM based designs as a "step up" uC in many ways... much more robust and forgiving for hobbyists, I feel. Oh well, dollars I suppose... SMD is obviously much more profitable for mass production runs.

Anyway... well done!