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.


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.



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);


//pinMode(backlight, OUTPUT);
//digitalWrite(backlight, HIGH);

if (client.connect()) {
                //pinMode(backlight, OUTPUT);
                //digitalWrite(backlight, HIGH);
                       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 */
                         delay(wait); /* wait for a response */
                        client.println("Subject:You Have Mail!!"); /* insert subject */

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

                        client.println("QUIT"); /* terminate connection */
                         delay(wait); /* wait for a response */
} else {

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

if (!client.connected()) {

Rob Glinka

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

They require authentication, but not SSL/TLS.



Go Up