Pages: 1 [2]   Go Down
Author Topic: Need help getting Arduino to send email  (Read 16691 times)
0 Members and 2 Guests are viewing this topic.
London
Offline Offline
Sr. Member
****
Karma: 1
Posts: 330
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Im with Virgin previously blueyonder here in the UK and they want authentication for pop and smtp.

Gordon
Logged

London, Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 90
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


I understand the need for authentication for pop, or auth for smtp if you are not on your ISP's ip range but if auth is required for the arduino then it becomes a complex problem.  Authenticated SMTP is more than just sending a plain-text password.

do a wiki of auth-smtp for more details.
Logged

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

The arduino cannot do TLS or SSL.  Those are too much to expect from an 8 bit microcontroller.  (Of course as soon as I say that, follower will find an example of someone who has already done it. smiley )

See if your ISP will allow a direct unauthenticated unencrypted port 25 SMTP connection.

-j

Logged

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

Thank you guys it is now complete!!! I am submitting it for reference if anyone else would like to play around with sending emails.  The *'s are used to hide personal data that will need to be inputted to make the program function.

[glow]/*
SEND AN EMAIL WITH ARDUINO

This code was created by modifying the connect example from arduino.cc and with the help of the YABB forums and their very helpful members.
This code sends an email to any email address and then disconnects.  It will also print on screen (in the serial monitor) the data the server sends the Arduino.  Make sure to replace all the *'s with your own information.
*/

#include <Ethernet.h>

byte mac[] = { 0x*, 0x*, 0x*, 0x*, 0x*, 0x* }; // Arduino's artificial mac address
byte ip[] = { *, *, *, * }; // my ip
byte server[] = { *, *, *, * }; // my smtp server ip
int time = 5000;
int wait = 2000;


Client client(server, 25);

void setup()
{
  delay(time);
  
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
  if (client.connect()) {
                         Serial.println("connected");
    
                         client.println("HELO itismeletschat"); /* say hello (statement after helo is needed but irrelevant)*/
                           delay(wait); /* wait for a response */

                         client.println("MAIL From: eguld@youremail.com"); /* identify sender, this should be the same as the smtp server you are using */
                           delay(wait); /* wait for a response */

                         client.println("RCPT To: guld.enrico@therecipientsmail.com"); /* identify recipient */
                         delay(wait); /* wait for a response */

                         client.println("DATA");
                           delay(wait); /* wait for a response */
  
                         client.println("To: guld.enrico@therecipientsmail.com"); /* identify recipient */
                         client.println("Subject: You Have Mail!!"); /* insert subject */

                         client.println("Please let me know it worked!!!"); /* insert body */
                         client.println("."); /* end email */
                  
                         client.println("QUIT"); /* terminate connection */
                          delay(wait); /* wait for a response */

  
    client.println();
    
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;smiley-wink
      ;
  }
}[/glow]

Thanks again,

-Enrico
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The arduino cannot do TLS or SSL.  Those are too much to expect from an 8 bit microcontroller.  (Of course as soon as I say that, follower will find an example of someone who has already done it. :-) )
Is that going to be your new game? :-)

The closest I've discovered in my wanderings are the SHA-1 and HMAC-SHA-1 implementations I linked to from my Arduino and IRC page.

--Phil.
Logged

London, Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 90
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Logged

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

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
Logged

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

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

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

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
Logged

Pages: 1 [2]   Go Up
Jump to: