Can the Ethernet Shield send email?

I'm trying to make an alarm system that send you an email when the sensor is activated. Can the arduino thernet shield send email to an user of hotmail from an user of the same or other email company?

Yes, it can. You just need to write the sketch to do it.

Here is my email code for v1.0. Change the stuff like network settings, email server and email addresses in the code. I used a gmail email server ip, but you can only send to gmail email accounts with it. It will not forward (relay) email. Press 'e' to send.

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

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };  
IPAddress ip( 192, 168, 2, 2 );    
IPAddress gateway( 192, 168, 2, 1 );
IPAddress subnet( 255, 255, 255, 0 );

// gmail.com email server
IPAddress server( 74, 125, 65, 27 );

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet); 
  delay(2000);
  Serial.println("Ready. Press e to send");
}

void loop()
{
  byte inChar;

  inChar = Serial.read();

  if(inChar == 'e')
  {
      if(sendEmail()) Serial.println("Email sent");
      else Serial.println("Email failed");
  }
}

byte sendEmail()
{
  byte thisByte = 0;
  byte respCode;
  
  if (client.connect(server,25)) {
    Serial.println("connected");
  } else {
    Serial.println("connection failed");
    return 0;
  }

  if(!eRcv()) return 0;
  
  client.write("helo 1.2.3.4\r\n");

  if(!eRcv()) return 0;
  
  client.write("MAIL From: <myemail@mydomain.com>\r\n");
  
  if(!eRcv()) return 0;

  client.write("RCPT To: <youremail@yourdomain.com>\r\n");

  if(!eRcv()) return 0;

  client.write("DATA\r\n");

  if(!eRcv()) return 0;
  
  client.write("To: Your Name <yourname@yourdomain.com>\r\n");

  client.write("From: My Name <myemail@mydomain.com>\r\n");
  
  client.write("Subject: Arduino email test\r\n");
  
  client.write("This is from my Arduino!\r\n");
  
  client.write(".\r\n");

  if(!eRcv()) return 0;

  client.write("QUIT\r\n");

  if(!eRcv()) return 0;

  client.stop();
  
  Serial.println("disconnected");
  
  return 1;
}

byte eRcv()
{
  byte respCode;
  byte thisByte;
  
  while(!client.available()) delay(1);

  respCode = client.peek();

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  if(respCode >= '4')
  {
    efail();
    return 0;  
  }
  
  return 1;
}


void efail()
{
  byte thisByte = 0;

  client.write("QUIT\r\n");

  while(!client.available()) delay(1);

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  client.stop();
  
  Serial.println("disconnected");
}

Thanks a lot man,but I haven't try it yet because of a problem. When I connect the Arduino to the laptop the device manager doesn't detect it. What could be that?

Did it ever work, then stop working, or is this a brand new install? Is there anything in Device Manager about unknown devices?

Yes it work before,but out of nothing stop working. In device manager don't appear anything.

This is my take on the subject

#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = { 192, 168, 2, 15 };
byte server[] = { 212,74,100,35};  // Tiscali.co.uk (TalkTalk) smtp server
int wait = 100;
Client client(server, 25);

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

void send_event(char *event)
{
  Serial.println("connecting...");
  if (client.connect()) {
    Serial.println("connected");
    client.println("HELO yous@your isp"); /* say hello*/
    delay(wait); /* wait for a response */
    client.println("MAIL From:<yous@your isp>"); /* identify sender */
    delay(wait); /* wait for a response */
    client.println("RCPT To:<destination@ isp>"); /* identify recipient */
    delay(wait); /* wait for a response */
    client.println("DATA"); 
    delay(wait); /* wait for a response */
    client.println("Subject: Arduino!!"); /* insert subject */
    client.println("FROM:<yous@your isp>");
    client.println("TO:<destination@isp>");
    client.println(event); /* insert body */
    client.println("."); // end message
    client.println("QUIT"); /* terminate connection */
    delay(wait); /* wait for a response */
    client.println();
    Serial.println("disconnecting.");
    client.stop();
  } 
  else 
  {
    Serial.println("connection failed");
  }
}

void loop()
{
  if( analogRead(0)<=100)
   {
     send_event("AN0 Triggered");
     delay(1000);
   }
     
     if( analogRead(1)<=100)
   {
     send_event("AN1 Triggered");
     delay(1000);
   }
}

This code sends a custom message depending on the trigger, in this case there are two triggers

if( analogRead(0)<=100)    // trigger
   {
     send_event("AN0 Triggered");   // call send_event and pass message AN0 Triggered to it
     delay(1000);  // this delay is to stop me spamming myself , a reset trigger should go here
   }
     
     if( analogRead(1)<=100)
   {
     send_event("AN1 Triggered");
     delay(1000);
   }
void send_event(char *event)

char *event contains the message and passes it to

    client.println(event); /* insert body */

In "perfect world", that works well. In "real world", it will crash like the Hindenburg. OH!! The humanity!!

You MUST evaluate each response from the email server. But what do I know? I've only had my own email servers for the last 12 years.

It works

Really? Load your code above, without changing ANYTHING. No email addresses. Nothing. Does it send the email?

Thanks a lot. I will try it when I get my new Mega. Can somebody tell my if it work? My project consist of various sensor that when activate send the email.