Pages: [1] 2   Go Down
Author Topic: Email using Ethernet Shield?  (Read 17603 times)
0 Members and 1 Guest are viewing this topic.
Louisville, KY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: August 12, 2009, 02:07:54 pm by tkj » Logged

Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Louisville, KY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can telnet into your mail server.
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Denmark (Europe)
Offline Offline
Full Member
***
Karma: 0
Posts: 198
Electronics Designer & Consultant
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Need any help with your electronics projects?
TKJ Electronics, a consultancy company located in Denmark (Europe), has the required ex

Louisville, KY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
$
« Last Edit: August 12, 2009, 04:13:33 pm by kg4wsv » Logged

Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 218
You will become one with the Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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(;smiley-wink
      ;
  }
}

Note:  I haven't tested this on my Ether-shield yet...  May need some tweaking...
« Last Edit: August 12, 2009, 07:08:37 pm by Spinlock » Logged

Louisville, KY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Louisville, KY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks
Logged

Pages: [1] 2   Go Up
Jump to: