hello brothers
i make my computer mail server to send to gmail because we cant use port 25 , and it success when i connect by telnet
then now no problem to connect to gmail
when i make in arduino it didnt establish the connection any one know wheres the problem ?
#include <Ethernet.h>
#include <SPI.h>
#include <EthernetClient.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xF6, 0x8D };
IPAddress ip(192,168,1,20); //arduino ip address
IPAddress server(192,168,1,2); //my email server (localhost)
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 25)) {
Serial.println("connected");
client.println("helo stelios.com");
Serial.println("helo");
client.println("auth login");
client.println("ZW5nLjNvdWZAZ21haWwuY29t"); // this is my email
client.println("*********************"); // this is password but i change it to ******
client.println("MAIL FROM: eng.3ouf@gmail.com");
client.println("rcpt to: asdouf@gmail.com");
client.println("data");
client.println("Subject: first mail!");
client.println("This is a mail body from Arduino!");
client.println(".");
} 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(;;)
;
}
}
i see all posts in forum , all problems focus in “cant telnet gmail account because port 25 is not supported by ISP”
then i solve it by making my computer to route this and i tested to telnet gmail from another computer in local network it success
this mean the problem of telnet gmail i solved , but the code didnt work in arduino :(((((
Code previously posted by others.
#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");
}
still not working
i cant understand how it work via telnet and not work via arduino !!!!
still not working
If you are using the email code zoomkat suggested, where does it not work? It will display all the responses from the server.
edit: Here is a link to my latest email code. It has a timeout now.
http://playground.arduino.cc/Code/Email
system
May 3, 2013, 12:09pm
#7
it work in telnet CMD in my pc and server is replay perfectly !
but in arduino didn't work ! how come!
Mohamed_Aouf:
it work in telnet CMD in my pc and server is replay perfectly !
but in arduino didn't work ! how come!
OK, since you are hesitant to post the problem, I'll start with the basics.
Is your ethernet shield connected to a router with a CAT5 cable? It must be connected to the internet to work.
system
May 3, 2013, 12:39pm
#9
yes , it work fine , i tested WEB SERVER example and it work fine
OK, are the network settings for the email code the same as you used for the web server?
system
May 3, 2013, 12:50pm
#11
when i ping ip of arduino it replay
system
May 3, 2013, 12:51pm
#12
of course the same IP AND every thing
I like the screen shots. Post one of the serial monitor after an email send attempt.
system
May 3, 2013, 1:03pm
#14
every time , connection failed to open
this mean no command written in telnet
What are you using for the email server ip/domain? Are you using a domain name or an ip?
system
May 3, 2013, 1:14pm
#16
i use my local computer as smtp server (192.168.1.2)
(in the 1# post i attach 2 pic that it success to connect )
Mohamed_Aouf:
i use my local computer as smtp server (192.168.1.2)
What email server program do you have installed in your local computer? Is it Exchange? Sendmail? PostFix?
Is your computer firewall allowing port 25 requests?
system
May 3, 2013, 1:22pm
#18
i use hMailserver to bypath routing between gmail account
do u know any server to use to check ?
i want only to establish connection between any server
Then try the gmail email server directly. You should use a local gmail server, so do an nslookup for the ip. From a command prompt
nslookup
set query=mx
gmail.com
It should list a few email servers. Use the one with the lowest MX preference number. Here is mine:
C:\Documents and Settings\user>nslookup
Default Server: ip68-105-28-16.at.at.cox.net
Address: 68.105.28.16
set query=mx
gmail.com
Server: ip68-105-28-16.at.at.cox.net
Address: 68.105.28.16
Non-authoritative answer:
// here is the lowest MX preference
gmail.com MX preference = 5, mail exchanger = gmail-smtp-in.l.google.com
gmail.com MX preference = 10, mail exchanger = alt1.gmail-smtp-in.l.google.com
gmail.com MX preference = 20, mail exchanger = alt2.gmail-smtp-in.l.google.com
gmail.com MX preference = 30, mail exchanger = alt3.gmail-smtp-in.l.google.com
gmail.com MX preference = 40, mail exchanger = alt4.gmail-smtp-in.l.google.com
gmail.com nameserver = ns4.google.com
gmail.com nameserver = ns1.google.com
gmail.com nameserver = ns2.google.com
gmail.com nameserver = ns3.google.com
// Here is the ip for that sever. Use it, but the one your nslookup shows
gmail-smtp-in.l.google.com internet address = 74.125.134.26
gmail-smtp-in.l.google.com AAAA IPv6 address = 2607:f8b0:4002:c02::1b
alt1.gmail-smtp-in.l.google.com internet address = 74.125.131.26
alt1.gmail-smtp-in.l.google.com AAAA IPv6 address = 2607:f8b0:400c:c02::1a
alt2.gmail-smtp-in.l.google.com internet address = 173.194.66.26
alt3.gmail-smtp-in.l.google.com internet address = 173.194.65.27
alt3.gmail-smtp-in.l.google.com AAAA IPv6 address = 2a00:1450:4013:c00::1a
alt4.gmail-smtp-in.l.google.com internet address = 173.194.70.26
alt4.gmail-smtp-in.l.google.com AAAA IPv6 address = 2a00:1450:4001:c02::1a
ns1.google.com internet address = 216.239.32.10
ns2.google.com internet address = 216.239.34.10
ns3.google.com internet address = 216.239.36.10
ns4.google.com internet address = 216.239.38.10
C:\Documents and Settings\user>
system
May 3, 2013, 3:04pm
#20
this is cmd
ip didnt appear