Pages: [1] 2 3   Go Down
Author Topic: Email Send Error  (Read 7937 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sending an email using Arduino Mega2560 with ethernet shield but I'm receiving and error after "sending". The error is :

Quote
Email Sent
220 BLU0-SMTP174.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Fri, 4 May 2012 19:05:14 -0700
501 5.5.4 Invalid Address
530 5.7.0 Must issue a STARTTLS command first

The code is
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };//Ethernet Shiel MAC
IPAddress ip( 1**, 1**, 1**, 1** );//IP Address of the connecting network   
IPAddress gateway( 1**, 1**, 1**, 1** );
IPAddress subnet ( 1**, 1**, 1**, 1** );
IPAddress server (65,55,162,200);//Hotmail IP Address Server
int x= 1000000;
int y=5000;

EthernetClient client;

void setup()
{
  delay(y);
  Serial.begin(9600);
  Ethernet.begin(mac,ip);
  delay (y);
  Serial.println ("connecting");
  delay(y);
  if (client.connect (server,25)) {
    Serial.println ("connected");
    client.write ("HELO hotmail.com");
    delay (x);
    client.write ("AUTH");
    delay(x);
    client.write (""); //user aut.
    delay(x);
    client.write ("");// password aut.
    delay(x);
     client.write ("Mail From:<@hotmail.com>");
     Serial.println ("Mail from");
    delay(x);
    client.write ("RCPT To:<@gmail.com>");
     Serial.println ("Mail To");
    delay(x);
    client.write ("DATA");
     Serial.println ("Data");
    delay(x);
    client.write ("From:<@hotmail.com>");
    Serial.println ("From");
    delay(x);
    client.write ("To:<@gmail.com");
    Serial.println ("To");
    delay(x);
    client.write ("Subject: ");
     Serial.println ("Subject");
    delay(x);
    client.write ("Trial");
    delay(x);
    client.println ();
    client.write ("Espero que alla funcionado");
    Serial.println ("Body");
    delay(x);
    client.println ("Quit");
    delay(x);
    Serial.println("Email Sent");
   
 } 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(;;)
     ;
 }
}

 
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
501 5.5.4 Invalid Address
530 5.7.0 Must issue a STARTTLS command first

To send email to a destination address other than Hotmail, you must authenticate with your user and password, but it requires Transport Layer Security (TLS) to do that. The ethernet shield library has no TLS capability.
http://en.wikipedia.org/wiki/Email_encryption
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have to authenticate the user name and password from the sending or receiving email?
I took other examples program that says it works,then there is no way I could send an email to either hotmail to hotmail, gmail to gmail or combined?
There is a way to make ethernet shield compatible with TLS?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change network settings and email addresses. Look for "// change this" comments.
Code:
#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;

// change this ip to your public ip
  client.write("helo 1.2.3.4\r\n");

  if(!eRcv()) return 0;

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

// change this  
  client.write("RCPT To: <youremail@gmail.com>\r\n");

  if(!eRcv()) return 0;

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

  if(!eRcv()) return 0;

//change this
  client.write("To: You <youremail@gmail.com>\r\n");

// change this
  client.write("From: Me <myemail@gmail.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");
}

edit: My apology in advance for any typos. I had to edit out my settings. I just returned from surfing and I need to get some surf wax and something to eat now.  smiley
« Last Edit: May 05, 2012, 01:45:55 pm by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In ther part that says
Quote
// change this ip to your public ip
  client.write("helo 1.2.3.4\r\n");
What I change there?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Replace 1.2.3.4 with your public ip. Itis normally the one assigned to the WAN interface on your router.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the respond I get
Quote
Ready. Press 'e' to send
connected
220 mx.google.com ESMTP i7sm19636491ani.17
250 mx.google.com at your service
530 5.7.0 Must issue a STARTTLS command first. i7sm19636491ani.17
221 2.0.0 closing connection i7sm19636491ani.17
disconnected
Email failed
Using the code you give as
Code:
#include <SPI.h>
#include <Ethernet.h>

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

// gmail.com email server
IPAddress server( 74, 125, 45, 109 );
int x=5000;
int y=20000;

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(x);
  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;

// change this ip to your public ip
  client.write("helo 70.45.71.79\r\n");

  if(!eRcv()) return 0;

// change this
  client.write("MAIL From: <@gmail.com>\r\n");
 
  if(!eRcv()) return 0;

// change this 
  client.write("RCPT To: <@gmail.com>\r\n");

  if(!eRcv()) return 0;

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

  if(!eRcv()) return 0;

//change this
  client.write("To: You <@gmail.com>\r\n");

// change this
  client.write("From: Me <@gmail.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(x);

  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");
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
530 5.7.0 Must issue a STARTTLS command first. i7sm19636491ani.17
That is asking you to start TLS, but you can't. There must be something about your email addresses that is not correct. I am on a different computer now. Give me a second and I will try the code and post my output.

I used the same code and server/port with my gmail account, and here is the output
Quote
Ready
connected
220 mx.google.com ESMTP e5si4439592anh.161
250 mx.google.com at your service
250 2.1.0 OK e5si4439592anh.161
250 2.1.5 OK e5si4439592anh.161
354  Go ahead e5si4439592anh.161
250 2.0.0 OK 1336249314 e5si4439592anh.161
221 2.0.0 closing connection e5si4439592anh.161
disconnected
Email sent

...and DING! My Blackberry says there is email in my Gmail account.

edit: By the place it asked for that TLS on your attempt, it must not like your FROM email address or your ip address.

Does your ISP have an email server you can send through? It may take email from the ips in its "localnet".
« Last Edit: May 05, 2012, 03:32:22 pm by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does your ISP have an email server you can send through? It may take email from the ips in its "localnet".

My ISP don't give me any email server,I'm form Puerto Rico. I don't know if here the ISP works diferent.

Quote
edit: By the place it asked for that TLS on your attempt, it must not like your FROM email address or your ip address.

What do you mean there? My email is working account and the IP I'm using is one random by the router original ip address?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where the server sent that 530 response is after the Arduino code sent the FROM email address. It had not even told the server what email address you wanted to send to. It didn't get that far.

That is why I use this code. That is normally the response if you use port 465 or 587, not port 25. You left the port set to 25 correct? Let me break it down.

Quote
220 mx.google.com ESMTP e5si4439592anh.161
// You send helo
250 mx.google.com at your service
// You send "MAIL From:". Here is where the 503 error was returned on yours.
250 2.1.0 OK e5si4439592anh.161
// You send "RCPT To:"
250 2.1.5 OK e5si4439592anh.161
// You send "DATA"
354  Go ahead e5si4439592anh.161
// You send the email with those to, from, and subject sends
// with a period on its own line as the terminator
250 2.0.0 OK 1336249314 e5si4439592anh.161
// You send "QUIT"
221 2.0.0 closing connection e5si4439592anh.161
// You client.stop()
disconnected
Email sent
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I use the port 25. So the problem can be in the port that I'm using? Because if the email is a real email form gmail and don't recognizes maybe is the port or the ip server. I'm using in command prompt ping smtp.gmail.com .
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You do not have a connection problem. All looks good until you send the "MAIL From:". That is when you are getting the 530 error about the TLS. You are getting an error message from the server. There is no connection problem. It is a ip/spam blocker/protocol challenge.

Maybe you should use nslookup and see if there is another gmail email server ip for your area. It should be the MX entry.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok thank you,but sorry for this....how do I look up for that nslookup?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My bad. It is a bit complex. From a command prompt
Code:
nslookup
set query=any
gmail.com

You should see a list of "MX preference = X mail exchanger = servername". Find the lowest number. Then below that is a list of those servernames with the ip of each.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot mannnn!!!! You are my hero jajajajaja
Logged

Pages: [1] 2 3   Go Up
Jump to: