idp1
April 24, 2016, 11:55am
#1
hi anyone can do me a favor ? i was finding information like sending the text file in the SD card (attached on arduino + ethernet) to email
i wonder is that even possible ?
i heard about SMTP2GO but though i follow the code exactly the same, ii get 'connection failed and E_mail failed"
anyone can help?
idp1
April 24, 2016, 12:11pm
#3
oh sorry my bad… here it is
/*
Email client sketch for IDE v1.0.5 and w5100/w5200
Posted 7 May 2015 by SurferTim
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE2, 0xA3 };
// change network settings to yours
IPAddress ip( 192, 168, 1, 7 );
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );
char server[] = "mail.smtp2go.com"; //smtpcorp.com
int port = 2525;
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(4,OUTPUT); //4
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip);
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, port) == 1) { //25,8025,587
Serial.println("connected");
} else {
Serial.println("connection failed");
return 0;
}
if(!eRcv()) return 0;
Serial.println("Sending hello");
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 192.168.1.7");
if(!eRcv()) return 0;
Serial.println("Sending auth login");
client.println("auth login");
if(!eRcv()) return 0;
Serial.println("Sending User");
// Change to your base64 encoded user
client.println("aWRwMXV0u7aG1AZ21ashaWwuY29t");
if(!eRcv()) return 0;
Serial.println("Sending Password");
// change to your base64 encoded password
client.println("d29vd2Vpaaa2Feqwp");
if(!eRcv()) return 0;
// change to your email address (sender)
Serial.println("Sending From");
client.println("MAIL From: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
// change to recipient address
Serial.println("Sending To");
client.println("RCPT To: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
Serial.println("Sending DATA");
client.println("DATA");
if(!eRcv()) return 0;
Serial.println("Sending email");
// change to recipient address
client.println("To: You <idp1uthm@gmail.com>");
// change to your address
client.println("From: Me <idp1uthm@gmail.com>");
client.println("Subject: Arduino email test\r\n");
client.println("This is from my Arduino!");
client.println(".");
if(!eRcv()) return 0;
Serial.println("Sending QUIT");
client.println("QUIT");
if(!eRcv()) return 0;
client.stop();
Serial.println("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("\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("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"));
}
Are you sure the DNS server (your router) will resolve a domain name? That will cause a fail. Change your connect code to the code below. It does a better job at error checking.
// change this
if(client.connect(server, port) == 1) {
// to this
int rtnVal = client.connect(server,port);
if(rtnVal != 1) {
if(rtnVal < 0) Serial.println("DNS fail");
else Serial.println("Connection failed");
}
else {
// do connection success here
If the DNS is failing, try getting an IP with DHCP rather than setting it with the static settings. It may be your router will not resolve domain names (no DNS server onboard).
edit: Chances are those network settings may not be correct for your localnet. try DHCP instead of static.
idp1
April 24, 2016, 2:19pm
#5
i modified the code as what you said, still i get 'Connection failed"
/*
Email client sketch for IDE v1.0.5 and w5100/w5200
Posted 7 May 2015 by SurferTim
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE2, 0xA3 };
// change network settings to yours
IPAddress ip( 192, 168, 1, 1 );
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );
char server[] = "mail.smtp2go.com"; //smtpcorp.com
int port = 2525;
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(53,OUTPUT); //4
digitalWrite(53,HIGH);
Ethernet.begin(mac, ip);
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;
int rtnVal = client.connect(server,port);
if(rtnVal != 1) {
if(rtnVal < 0){ Serial.println("DNS fail");
}
else {Serial.println("Connection failed");
} }
else {
Serial.println("connected");
return 0;
}
if(!eRcv()) return 0;
Serial.println("Sending hello");
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 175.141.175.199");
if(!eRcv()) return 0;
Serial.println("Sending auth login");
client.println("auth login");
if(!eRcv()) return 0;
Serial.println("Sending User");
// Change to your base64 encoded user
client.println("aWRwMXV0aG1AZ22sdtsas1haWwuY29t");
if(!eRcv()) return 0;
Serial.println("Sending Password");
// change to your base64 encoded password
client.println("d29vd2VpAkx7fa2Fp");
if(!eRcv()) return 0;
// change to your email address (sender)
Serial.println("Sending From");
client.println("MAIL From: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
// change to recipient address
Serial.println("Sending To");
client.println("RCPT To: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
Serial.println("Sending DATA");
client.println("DATA");
if(!eRcv()) return 0;
Serial.println("Sending email");
// change to recipient address
client.println("To: You <idp1uthm@gmail.com>");
// change to your address
client.println("From: Me <idp1uthm@gmail.com>");
client.println("Subject: Arduino email test\r\n");
client.println("This is from my Arduino!");
client.println(".");
if(!eRcv()) return 0;
Serial.println("Sending QUIT");
client.println("QUIT");
if(!eRcv()) return 0;
client.stop();
Serial.println("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("\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("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"));
}
Did you try using a DHCP IP rather than static?
// change this
Ethernet.begin(mac, ip);
// to this
if(Ethernet.begin(mac) == 0) Serial.println("DHCP failed");
else Serial.println(Ethernet.localIP());
idp1
April 24, 2016, 3:16pm
#7
arh sorry there was an error in the previous step the actual error i get is this
:DNS fail
:Timeout
:Email failed
the code is the same, i change the ip according to DHCPserver (from cmmd prompt there)
sorry for my stupidity, i’m actually new to this field…
/*
Email client sketch for IDE v1.0.5 and w5100/w5200
Posted 7 May 2015 by SurferTim
*/
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE2, 0xA3 };
// change network settings to yours
IPAddress ip( 192, 168, 1, 1 );
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );
char server[] = "mail.smtp2go.com"; //smtpcorp.com
int port = 2525;
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(53,OUTPUT); //4
digitalWrite(53,HIGH);
Ethernet.begin(mac, ip);
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;
int rtnVal = client.connect(server,port);
if(rtnVal != 1) {
if(rtnVal < 0){ Serial.println("DNS fail");
}
else {Serial.println("Connection failed");
} }
else {
Serial.println("connected");
return 0;
}
if(!eRcv()) return 0;
Serial.println("Sending hello");
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 175.141.175.199");
if(!eRcv()) return 0;
Serial.println("Sending auth login");
client.println("auth login");
if(!eRcv()) return 0;
Serial.println("Sending User");
// Change to your base64 encoded user
client.println("aWRwMXV0aG1AZ2asas211haWwuY29t");
if(!eRcv()) return 0;
Serial.println("Sending Password");
// change to your base64 encoded password
client.println("d29vd2Vpa223GtyFp");
if(!eRcv()) return 0;
// change to your email address (sender)
Serial.println("Sending From");
client.println("MAIL From: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
// change to recipient address
Serial.println("Sending To");
client.println("RCPT To: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
Serial.println("Sending DATA");
client.println("DATA");
if(!eRcv()) return 0;
Serial.println("Sending email");
// change to recipient address
client.println("To: You <idp1uthm@gmail.com>");
// change to your address
client.println("From: Me <idp1uthm@gmail.com>");
client.println("Subject: Arduino email test\r\n");
client.println("This is from my Arduino!");
client.println(".");
if(!eRcv()) return 0;
Serial.println("Sending QUIT");
client.println("QUIT");
if(!eRcv()) return 0;
client.stop();
Serial.println("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("\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("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"));
}
The new code you posted above won't work. The ip and gateway variables cannot be the same. Besides, you aren't using the gateway variable in the begin function call.
Use DHCP to get the network settings for your Arduino.
idp1
April 24, 2016, 4:10pm
#9
i’m getting confused… lets restart everything ok? right now i have the code:
/*
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xE2, 0xA3 };
// change network settings to yours
IPAddress ip( 192, 168, 1, 9 );
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );
char server[] = "mail.smtp2go.com"; //smtpcorp.com
int port = 2525;
EthernetClient client;
void setup()
{
Serial.begin(9600);
pinMode(53,OUTPUT); //4
digitalWrite(53,HIGH);
Ethernet.begin(mac, ip);
if(Ethernet.begin(mac) == 0) {Serial.println("DHCP failed");}
else {Serial.println(Ethernet.localIP());}
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;
int rtnVal = client.connect(server,port);
if(rtnVal != 1) {
if(rtnVal < 0){ Serial.println("DNS fail");
}
else {Serial.println("Connection failed");
} }
else {
Serial.println("connected");
return 0;
}
if(!eRcv()) return 0;
Serial.println("Sending hello");
// replace 1.2.3.4 with your Arduino's ip
client.println("EHLO 198.168.1.9");
if(!eRcv()) return 0;
Serial.println("Sending auth login");
client.println("auth login");
if(!eRcv()) return 0;
Serial.println("Sending User");
// Change to your base64 encoded user
client.println("aWRwMXV0aG1AZ21haWwuY29t");
if(!eRcv()) return 0;
Serial.println("Sending Password");
// change to your base64 encoded password
client.println("d29vd2Vpa2Fp");
if(!eRcv()) return 0;
// change to your email address (sender)
Serial.println("Sending From");
client.println("MAIL From: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
// change to recipient address
Serial.println("Sending To");
client.println("RCPT To: <idp1uthm@gmail.com>");
if(!eRcv()) return 0;
Serial.println("Sending DATA");
client.println("DATA");
if(!eRcv()) return 0;
Serial.println("Sending email");
// change to recipient address
client.println("To: You <idp1uthm@gmail.com>");
// change to your address
client.println("From: Me <idp1uthm@gmail.com>");
client.println("Subject: Arduino email test\r\n");
client.println("This is from my Arduino!");
client.println(".");
if(!eRcv()) return 0;
Serial.println("Sending QUIT");
client.println("QUIT");
if(!eRcv()) return 0;
client.stop();
Serial.println("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("\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("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"));
}
this time i get connected but Email field:
192.168.1.9
Ready. Press ‘e’ to send.
connected
Email failed
*i didnt include gateway in the begin function because i saw from example saying that there are optional… is it ?
Wrong email server name.
// change this
char server[] = "mail.smtp2go.com"; //smtpcorp.com
// to this
char server[] = "smtp2go.com"; //smtpcorp.com
idp1
April 24, 2016, 4:20pm
#11
wa... tyty SurferTim you are so great... i finally able to accept the message at my gmail.... ty SurferTim... you make my day ^^
Thank you for everything~
idp1, paste that complete code that works, please