Go Down

Topic: Need help getting Arduino to send email (Read 17 times) previous topic - next topic

Mark Bramwell

I am surprised it worked.  SMTP usually requires a blank line between the headers and the main body of the message.  Are you sure you didn't send a blank line after the subject and before your message text? The headers are also missing a FROM: line.  Most systems can deal with a missing DATE: line.



eguld

yeah besides replacing the ip and mac addresses with *'s and changing the email addresses to not my own the code is exactly as I used it.  In the links posted earlier in this post they did not mention a space before the body, a Date: line, or a FROM: line and as a result I never bothered using them (mostly because I was trying to avoid a complicated code).  Furthermore, when I was using the telnet command from my laptop I did not leave a blank line.

Also, there was no need for authentication, which would have been a nightmare.

-Enrico

gilweb

I know this is an old topic but just incase if will help someone in the future I figured I would post anyway.

You forgot a few key lines in your Telnet session.  Also, everyone is correct you will need add the security if you want to email gmail directly.  I build a windows SMTP server inside my LAN so I was able to avoid using any security, but then my SMTP server communicates to Gmail securely.  I did not go through all the code just changed the top lines and started adding my code for my LCD.

Here is the updated code.  This works and my Arduino send email directly to my SMTP server.

#include <Ethernet.h>
//#include <LiquidCrystal.h>

byte mac[] = { 0x00, 0x23, 0xc9, 0x8e, 0x77, 0xb4 };
byte ip[] = { 1*, 4*, 2*, 2** };
byte gateway[] = { 1*, 4*, 1*, 2 };
byte server[] = { 1*, 4*, 1*, 1* }; // Mailserver
byte subnet[] = { 255, 255, 240, 0 };
int time = 5000;
int wait = 1000;

//LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

//int backlight = 13;

Client client(server, 25);

void setup()
{
delay(time); /* allow the router to identify the Arduino before the Arduino connects to the internet */

Ethernet.begin(mac, ip, gateway, subnet);

delay(1000);

//pinMode(backlight, OUTPUT);
//digitalWrite(backlight, HIGH);
//lcd.begin(2,16);
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("connectting...");

if (client.connect()) {
                //pinMode(backlight, OUTPUT);
                //digitalWrite(backlight, HIGH);
                //lcd.begin(2,16);
                //lcd.clear();
                //lcd.setCursor(0,0);
                //lcd.print("connected...");
                         
 
                       client.println("HELO something.com"); /* say hello*/
                         delay(wait); /* wait for a response */
   
                       client.println("MAIL FROM:me@something.com"); /* identify sender */
                         delay(wait); /* wait for a response */
   
                       client.println("RCPT TO:you@gmail.com"); /* identify recipient */
                         delay(wait); /* wait for a response */
   
                       client.println("DATA");
                         delay(wait); /* wait for a response */
   
   
                        client.println("Subject:You Have Mail!!"); /* insert subject */
                        client.println("");

                        client.println("Sent from Arduino!!!"); /* insert body */
                        client.println(".");

                        client.println("QUIT"); /* terminate connection */
                         delay(wait); /* wait for a response */
                         
                         
 
 
  client.println();
 
} else {
   //lcd.begin(2,16);
   //lcd.clear();
   //lcd.setCursor(0,0);
   //lcd.print("disconnected...");
}
}

void loop()
{
if (client.available()) {
  char c = client.read();
  Serial.print(c);
}

if (!client.connected()) {
  Serial.println();
  Serial.println("disconnecting.");
  client.stop();
  for(;;)
    ;
}
}

Rob Glinka

Here's another example of a way to send SMTP over Yahoo's servers.

They require authentication, but not SSL/TLS.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250101892/15

Rob

Go Up