Go Down

Topic: Email using Ethernet Shield? (Read 19831 times) previous topic - next topic

Ron C

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!

Thomas Jespersen

#1
Aug 12, 2009, 09:07 pm Last Edit: Aug 12, 2009, 09:07 pm by tkj Reason: 1
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!
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Ron C

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.

EmilyJane

You can telnet into your mail server.

Thomas Jespersen

Quote
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!
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

kg4wsv

Quote
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

Thomas Jespersen

Quote
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!
Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Ron C

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???


kg4wsv

#8
Aug 12, 2009, 11:12 pm Last Edit: Aug 12, 2009, 11:13 pm by kg4wsv Reason: 1
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


$ telnet smtp.eng.uah.edu 25
Trying 146.229.162.18...
Connected to mercury.eng.uah.edu.
Escape character is '^]'.

220 eng.uah.edu ESMTP Sendmail 8.13.8+Sun/8.13.8; Wed, 12 Aug 2009 16:04:25 -0500 (CDT)
HELO eng.uah.edu
250 eng.uah.edu Hello flat-mac [1.2.3.4], pleased to meet you
MAIL From:<auser@eng.uah.edu>
250 2.1.0 <auser@eng.uah.edu>... Sender ok
RCPT To:<otheruser@eng.uah.edu>
250 2.1.5 < otheruser@eng.uah.edu>... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: my message

did you notice that the subject is part of the text?  
.

250 2.0.0 n7CL4PA0007387 Message accepted for delivery
QUIT
221 2.0.0 eng.uah.edu closing connection
Connection closed by foreign host.
$

Spinlock

#9
Aug 13, 2009, 02:07 am Last Edit: Aug 13, 2009, 02:08 am by Spinlock Reason: 1
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.

Quote

#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(;;)
     ;
 }
}


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

Ron C

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...


kg4wsv

Quote
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

Ron C

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

Jed42

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


Go Up