Email using Ethernet Shield?

Is the Arduino Ethernet shield capable of generating emails or is it limited HTTP requests?

I did not find any references to SMTP in the forum...

If it is possible, please post any code examples. I do not have an ethernet shield yet - just exploring the capabilities.

Thanks!

It’s not possible to make a SMTP request with the Ethernet shield.

But if you have a webserver you could make a PHP script which the Ethernet shield call, and then it sends the email. ← That’s what I’m doing!

Thanks for the information.

Unfortunately, my ISP is my cable company and they don’t allow any server-side scripting code. (sigh)

There are web server modules that will interface with a microcontroller, but not sure if they have any client/browser capabilities.

You can telnet into your mail server.

Unfortunately, my ISP is my cable company and they don't allow any server-side scripting code. (sigh)

You can get a webserver, which can do the PHP mail thing, for free! But then you are going to use their SMTP if not configured otherwise, which I don't know if it's possible on free servers!

It's not possible to make a SMTP request with the Ethernet shield

Why would you think that? Basic SMTP is a fairly simple protocol.

You may run into problems with authentication being required by your SMTP server, but SMTP in general isn't that tough.

-j

Why would you think that? Basic SMTP is a fairly simple protocol.

You may run into problems with authentication being required by your SMTP server, but SMTP in general isn't that tough.

Yes, it is... Indeed! It's pretty easy to connect to a SMTP server with a socket connection which the Ethernet board can handle - so yes, it's possible, but there isn't anyone who have made it yet!

Here's the commands you need to send to the server with the socket connection: http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol#SMTP_transport_example

Anyways, sorry for my wrong information. So it is possible to make a SMTP request from the Ethernet shield, but I think it's easier to make a PHP script and then call that to send an email!

Using telnet is certainly easy but what would the Arduino code look like to send SMTP requests?

I assume you would use the Client class and the print or write function from the Ethernet library, but what is the syntax for the request.

Something similar to the HTTP GET, POST, etc requests???

I don’t have an arduino sketch, but here is a sample telnet session where I talk to the SMTP server directly. Stuff in blue is the response from the server, red is what I send. Green is just telnet session overhead.

Note the SMTP responses are 3 digit codes followed by explanatory text. You can probably write a very robust client by interpreting the numbers and ignoring all the following text (which makes arduino the code simpler).

Note this in no way addresses the authentication you may have to do, but it would be handled similarly.

It also doesn’t address any encrypted links (e.g. TLS) which would be practically impossible on an arduino.

-j

[color=#00ff00]$ telnet smtp.eng.uah.edu 25
Trying 146.229.162.18...
Connected to mercury.eng.uah.edu.
Escape character is '^]'.[/color]
[color=#0000ff]220 eng.uah.edu ESMTP Sendmail 8.13.8+Sun/8.13.8; Wed, 12 Aug 2009 16:04:25 -0500 (CDT)[/color]
[color=#ff0000]HELO eng.uah.edu[/color]
[color=#0000ff]250 eng.uah.edu Hello flat-mac [1.2.3.4], pleased to meet you[/color]
[color=#ff0000]MAIL From:<auser@eng.uah.edu>[/color]
[color=#0000ff]250 2.1.0 <auser@eng.uah.edu>... Sender ok[/color]
[color=#ff0000]RCPT To:<otheruser@eng.uah.edu>[/color]
[color=#0000ff]250 2.1.5 < otheruser@eng.uah.edu>... Recipient ok[/color]
[color=#ff0000]DATA[/color]
[color=#0000ff]354 Enter mail, end with "." on a line by itself[/color]
[color=#ff0000]Subject: my message

did you notice that the subject is part of the text?  
.[/color]
[color=#0000ff]250 2.0.0 n7CL4PA0007387 Message accepted for delivery[/color]
[color=#ff0000]QUIT[/color]
[color=#0000ff]221 2.0.0 eng.uah.edu closing connection[/color]
[color=#00ff00]Connection closed by foreign host.
$ [/color]

This will do the functionality part. The next part is breaking the protocol into command/response and handling errors.

BTW : This will ONLY work if you know the IP address of the target domain’s mail servers. If you don’t, and until DNS appears, it would take quite a bit of work.

#include <Ethernet.h>

byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip = { 10, 0, 0, 177 };
byte server = { 64, 233, 187, 99 }; // Mail server address MODIFY THIS FOR THE TARGET DOMAIN’s MAIL SERVER

Client client(server, 25);

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

delay(1000);

Serial.println(“connecting…”);

if (client.connect()) {
Serial.println(“connected”);
client.println(“EHLO MYSERVER”);
client.println(“MAIL FROM:someone@somewhere.com”);
client.println(“RCPT TO:TheTarget@ThisDomain.com”);
client.println(“DATA”);
client.println(“SUBJECT: This is the subject”);
client.println();
client.println("This is the body.);
client.println(“This is another line of the body.”);
client.println(".");
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(;:wink:
;
}
}

Note: I haven’t tested this on my Ether-shield yet… May need some tweaking…

Thanks Spinlock and everyone else,

I wasn't sure how you would use the client class to initiate the telnet session.

I believe the first println should be HELO MYSERVER rather than EHLO... :)

I might order an ethernet shield to experiment with - looks like it could be interesting...

I believe the first println should be HELO MYSERVER rather than EHLO..

EHLO is actually valid, and gets you access to some extended functionality. HELO is probably fine for most thing you'd want to do with an arduino.

-j

kg4wsv,

Sorry, thought that was a TYPO! Learn something new every day.

Never really had much of an occasion to use telnet up till now...

Thanks

Has anyone gotten this to work? I want to hook up a water sensor in my basement, when water is detected I would like it to send a e-mail.

Thanks

thanks

Hi, yes I did get an email sent using this as a template.

From what I can figure out, you can’t send email using gmail because the arduino doesn’t have any ssl libraries, and gmail only allows for ssl/tls connections through their SMTP servers.

HOWEVER, yahoo.com DOES allow free open SMTP traffic if you use their mobile servers (the ones for smartphones like blackberries, droid, etc.)

So if you enter the IP address of their smtp.mobile.mail.yahoo.com server (98.136.86.109), and you authenticate (you have to send a username/password). Then you can send any email you want.

To authenticate, you have to send an encoded username/password, you can generate it on your computer and just copy/paste it into your arduino sketch.

So grab the info from here: qmail.jms1.net/test-auth.shtml - sorry, this is my first post, so the site won’t let me make this a link.
Basically it says to run a perl script with your info like this: perl -MMIME::Base64 -e 'print encode_base64("\000jms1\@jms1.net\000not.my.real.password")'

Then copy/paste the output into your sketch. Here’s my example:

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xAF, 0xCE, 0xDD }; // whatever mac you want
byte ip[] = { LOCAL IP ADDRESS };
byte server[] = { 98, 136, 86, 109 }; // Mail server address  (this is for yahoo's mobile smtp)

Client client(server, 587);  // yahoo's mobile smtp server ip/port

void setup()
{
 Ethernet.begin(mac, ip);
 Serial.begin(9600);
 
 delay(1000);
 
 Serial.println("connecting...");
 
 if (client.connect()) {
   Serial.println("connected");
   client.println("EHLO MYSERVER");
   client.println("AUTH PLAIN ************************************");  // replace the **'s with your auth info from the perl script.
   client.println("MAIL FROM:<email@email.email>");
   client.println("RCPT TO:<email@email.email>");
   client.println("DATA");
   client.println("From: <email@email.email>");
   client.println("TO: <email@email.email>");
   client.println("SUBJECT: This is the subject");
   client.println();
   client.println("This is the body.");
   client.println("This is another line of the body.");
   client.println(".");
   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(;;)
     ;
 }
}

Now this is actually my first Arduino sketch. It sends an email every time I hit the reset button. It seems to work for me, but as always, YMMV.

-Rob

Thanks a bunch I will try it soon. The link that you have there won't let me search for the info, any thoughts?

Well, there shouldn’t be much you need from that link. It’s just what I based my code off of.

http://qmail.jms1.net/test-auth.shtml

Mostly just the perl line at the top and the AUTH info at the top.

d

I created a Yahoo email acount, ran the perl to get my hashed userid/password, and have been trying to connect through telnet but it just keeps telling me Access Denied. This is killing me. What am I doing wrong?