system
August 28, 2013, 6:07pm
1
code below
i got a problem, it always timeout when i'm trying to send HELO to the SMTP server. i don't know why. Can someone help me plzz.
this is what i got want i run this code
Ready. Press 'e' to send.
connected
Timeout
Email failed
/*
Email client sketch for IDE v1.0.1 and w5100/w5200
Posted December 2012 by SurferTim
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
// change network settings to yours
IPAddress ip( x, x, x, x );
IPAddress gateway( 0, 0, 0, 0 );
IPAddress subnet( 255, 255, 255, 0 );
// change server to your email server ip or domain
char server[] = "smtpcorp.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, subnet);
delay(2000);
Serial.println(F("Ready. Press 'e' to send."));
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'e')
{
if(sendEmail()) Serial.println(F("Email sent"));
else Serial.println(F("Email failed"));
}
}
byte sendEmail()
{
byte thisByte = 0;
byte respCode;
if(client.connect(server,25)) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if(!eRcv()) return 0;
Serial.println(F("Sending helo"));
// change to your public ip
client.println(F("EHLO 1.2.3.4"));
if(!eRcv()) return 0;
Serial.println(F("Sending From"));
// change to your email address (sender)
client.println(F("MAIL From: <yo@hotmail.com>"));
if(!eRcv()) return 0;
// change to recipient address
Serial.println(F("Sending To"));
client.println(F("RCPT To: <yo@hotmail.com>"));
if(!eRcv()) return 0;
Serial.println(F("Sending DATA"));
client.println(F("DATA"));
if(!eRcv()) return 0;
Serial.println(F("Sending email"));
// change to recipient address
client.println(F("To: You <you@yourdomain.com>"));
// change to your address
client.println(F("From: Me <me@mydomain.com>"));
client.println(F("Subject: Arduino email test\r\n"));
client.println(F("This is from my Arduino!"));
client.println(F("."));
if(!eRcv()) return 0;
Serial.println(F("Sending QUIT"));
client.println(F("QUIT"));
if(!eRcv()) return 0;
client.stop();
Serial.println(F("disconnected"));
return 1;
}
byte eRcv()
{
byte respCode;
byte thisByte;
int loopCount = 0;
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return 0;
}
}
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;
int loopCount = 0;
client.println(F("QUIT"));
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return;
}
}
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
client.stop();
Serial.println(F("disconnected"));
}
i got the code from Arduino Playground - Email
Only the gateway subnet looks correct. If the ip is not public, don't obfuscate it.
IPAddress ip( x, x, x, x );
IPAddress gateway( 0, 0, 0, 0 );
IPAddress subnet( 255, 255, 255, 0 );
// change this
Ethernet.begin(mac, ip, gateway, subnet);
// to this
Ethernet.begin(mac, ip, gateway, gateway, subnet);
And even after correcting that, this smtpcorp.com server will probably not accept mail for hotmail.com addresses.
char server[] = "smtpcorp.com";
client.println(F("RCPT To: <yo@hotmail.com>"));
system
August 28, 2013, 9:07pm
3
And even after correcting that, this smtpcorp.com server will probably not accept mail for hotmail.com addresses.
Code:
char server[] = "smtpcorp.com ";
client.println(F("RCPT To: yo@hotmail.com "));
this hotmail is the address that i take to make my account on smtp2go so i think this should be alright.
nly the gateway looks correct. If the ip is not public, don't obfuscate it.
Code:
IPAddress ip( x, x, x, x );
IPAddress gateway( 0, 0, 0, 0 );
IPAddress subnet( 255, 255, 255, 0 );
Code:
// change this
Ethernet.begin(mac, ip, gateway, subnet);
// to this
Ethernet.begin(mac, ip, gateway, gateway, subnet);
sorry i forget that this ip wasn't my public ip.
thx i forget the second gateways but i still don't work. I like i don't receive anything from the server before my HELO.
I don't use smtp2go.com so someone else may need to help you with that.
For hotmail accounts, these are the current email servers:
mx1.hotmail.com
mx2.hotmail.com
mx3.hotmail.com
mx4.hotmail.com
edit: I have tested yahoo and gmail. Both work. I do not have a hotmail account to test for you.
system
August 28, 2013, 11:29pm
5
edit: I have tested yahoo and gmail. Both work. I do not have a hotmail account to test for you.
what's your code with gmail account ?
The same code in the link you provided in the original post, changing only what was specified on that page.
http://playground.arduino.cc/Code/Email
Here is a link to the yahoo email test serial output:
http://forum.arduino.cc/index.php?topic=177603.msg1343356#msg1343356
The gmail send was the same, except I used gmail-smtp-in.l.google.com as the server and my gmail address as the recipient.
system
August 29, 2013, 11:56am
7
Thanks for the email sketch SurferTim, I didn't know it was on the Playground.
I have already a working webpage. So my DHCP and gateway are already working.
I also update to ThingSpeak.com so I had already a 'client' class declared. I used the same 'client' class and added the part that sends the email. The SMTP server I used is the one supplied by my internet provider, which has no passord or encryption, they only check the IP to see if I am one of their clients. It worked right the first time. Thanks!
My webpage on the Arduino has a button and a form, which I use now to send an email.
system
August 29, 2013, 5:10pm
8
i always got timeout again, i don't receive come back from the server
/*
Email client sketch for IDE v1.0.1 and w5100/w5200
Posted December 2012 by SurferTim
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
// change network settings to yours
IPAddress ip( 192, 168, 0, 109 );
IPAddress gateway( 0, 0, 0, 0 );
IPAddress subnet( 255, 255, 255, 0 );
// change server to your email server ip or domain
// IPAddress server( 1, 2, 3, 4 );
char server[] = "gmail-smtp-in.l.google.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
delay(2000);
Serial.println(F("Ready. Press 'e' to send."));
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'e')
{
if(sendEmail()) Serial.println(F("Email sent"));
else Serial.println(F("Email failed"));
}
}
byte sendEmail()
{
byte thisByte = 0;
byte respCode;
if(client.connect(server,25)) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if(!eRcv()) return 0; //// it fail here
Serial.println(F("Sending helo"));
// change to your public ip
client.println(F("helo 1.2.3.4"));
if(!eRcv()) return 0;
Serial.println(F("Sending From"));
// change to your email address (sender)
client.println(F("MAIL From: <letnic2@hotmail.com>"));
if(!eRcv()) return 0;
// change to recipient address
Serial.println(F("Sending To"));
client.println(F("RCPT To: <letnic2@hotmail.com>"));
if(!eRcv()) return 0;
Serial.println(F("Sending DATA"));
client.println(F("DATA"));
if(!eRcv()) return 0;
Serial.println(F("Sending email"));
// change to recipient address
client.println(F("To: You <you@yourdomain.com>"));
// change to your address
client.println(F("From: Me <me@mydomain.com>"));
client.println(F("Subject: Arduino email test\r\n"));
client.println(F("This is from my Arduino!"));
client.println(F("."));
if(!eRcv()) return 0;
Serial.println(F("Sending QUIT"));
client.println(F("QUIT"));
if(!eRcv()) return 0;
client.stop();
Serial.println(F("disconnected"));
return 1;
}
byte eRcv()
{
byte respCode;
byte thisByte;
int loopCount = 0;
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return 0;
}
}
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;
int loopCount = 0;
client.println(F("QUIT"));
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("\r\nTimeout"));
return;
}
}
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
client.stop();
Serial.println(F("disconnected"));
}
system
August 29, 2013, 6:14pm
9
The email sketch by SurferTim is for advanced users. You have to know a little about the protocol.
This line: client.println(F("helo 1.2.3.4"));
requires you IP number on the internet.
You can request it here: http://whatismyipaddress.com/
SurferTim, is it possible to do that automatically ? My IP sometimes changes (once a year). How does a normal email client do that ?
system
August 29, 2013, 6:19pm
10
but i never got to this line it fail before that line, and i change it in my sketch but not on the forum.
system
August 29, 2013, 6:33pm
11
Is the SMTP connection failing ?
This line ? if(client.connect(server,25)
Or is the complete ethernet connection failing ?
This line ? Ethernet.begin(...
Could you try the webserver with DHCP sketch.
To see if you can create a webpage and connect to it with a browser.
That example is old, please use DHCP by omitting the 'ip' parameter and use Ethernet.begin( mac);
Tell us what the output of the serial monitor is.
system
August 29, 2013, 6:43pm
12
this is what i got
server is at 192.168.0.111
new client
GET / HTTP/1.1
Host: 192.168.0.111
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
and on the web page
analog input 0 is 1023
analog input 1 is 1023
analog input 2 is 681
analog input 3 is 512
analog input 4 is 468
analog input 5 is 399
system
August 29, 2013, 6:55pm
13
Very nice. The hardware and your router are okay.
The webserver example uses a different mac.
Your router assigns '111' to you with DHCP, while you sketch uses 109.
Could you try to slowly merge the sketches ?
Try your mac from the email sketch in the Webserver sketch.
After that, try to setup a DHCP connection in the email sketch.
If that is all okay, the SMTP server is not right.
Or is that what you already know ?
Could you try another SMTP server ?
I have hotmail and gmail, tell me if you want me to try something.
system
August 29, 2013, 7:09pm
14
when i put a dhcp connection like in the code, it fail at client.connect(server,25)
i want to send an e-mail to any account, i got gmail and hotmail account.
code with dhcp connection
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x59, 0x67 };
// change network settings to yours
IPAddress ip( 192, 168, 0, 110 );
IPAddress gateway( 0, 0, 0, 0 );
IPAddress subnet( 255, 255, 255, 0 );
// change server to your email server ip or domain
char server[] = "gmail-smtp-in.l.google.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac);
delay(2000);
Serial.println(F("Ready. Press 'e' to send."));
}
void loop()
{
byte inChar;
inChar = Serial.read();
if(inChar == 'e')
{
if(sendEmail()) Serial.println(F("Email sent"));
else Serial.println(F("Email failed"));
}
}
byte sendEmail()
{
byte thisByte = 0;
byte respCode;
if(client.connect(server,25)) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if(!eRcv()) return 0;
Serial.println(F("Sending helo"));
// change to your public ip
client.println(F("helo 1.2.3.4"));
Are you sure your dns is working? Try sending by ip. This is the ip for gmail-smtp-in.l.google.com .
IPAddress server(173,194,64,26);
edit: Some of these servers are dependent on your location. You should do a nslookup for your local servers. From a command prompt
nslookup
set query=mx
gmail.com
system
August 29, 2013, 11:48pm
16
I can connect to that server, using: telnet gmail-smtp-in.l.google.com 25
So I don't know what is going on.
system
August 30, 2013, 1:33am
17
with the ip address i'm still stuck at client.connect(server,25); then after connection failed and email failed
i got mx preference 5 for gmail-smtp-in.l.google.com and others are 10, 20, 30 and 40.
my goal with this project is send an e-mail to my cellphone at xxxxxxxx@msg.telus.com . So do we got a better way ?
It may be you are being blocked from sending email that way by your ISP, possibly as spam prevention. I can't explain why you cannot make a connection. If you were being blocked by the email server, it would allow you to make the connection, but would refuse the email later in that code.
I recommend contacting your ISP and ask about it. Explain what you are trying to do. Maybe you can use their email server as a relay.
system
August 30, 2013, 8:09am
19
It is also very hard to understand what is going on, without the real numbers and real output.
I run Ubuntu linux, and use telnet.
For example this (I typed the bold text, the 'myip' is my ip number on the internet):
telnet smtp.gmail.com 25
Trying 173.194.65.108...
Connected to gmail-smtp-msa.l.google.com .
Escape character is '^]'.
220 mx.google.com ESMTP p5sm236964eg.5 - gsmtp
EHLO 'myip'
250-mx.google.com at your service, ['myip']
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
QUIT
Connection closed by foreign host.
system
August 30, 2013, 6:47pm
20
This is what i always got.
Ready. Press 'e' to send.
connection failed
Email failed
I'm not able to connect to the server.