I'm having problems getting my ethernet shield to connect to anything on the internet. I'm trying to use it to send an email (see code below) but it never even connects and begins executing the email code; it just says connection failed. Any help would be appreciated. Notes: I used DHCP to obtain an IP address for the ethernet shield. In this code I'm trying to connect to SMTP2GO but I have tried other addresses like google, with no luck
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x5C, 0xAE }; //physical mac address
//byte ip[] = { 192, 168, 10, 241 }; // ip in lan
//byte gateway[] = { 192, 168, 10, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte smtp[] = "mail.smtp2go.com";
EthernetClient client;
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
}
// print your local IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
Serial.print("My gateway address: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("My Subnet: ");
Serial.println(Ethernet.subnetMask());
Ethernet.begin(mac,'Ethernet.localIP()','Ethernet.gatewayIP()','Ethernet.subnetMask()');
Serial.println("connecting...");
if (client.connect(smtp,2525)) {
Serial.println("connected");
client.println("EHLO 'Ethernet.localIP()'");
client.println("AUTH LOGIN"); //see "http://base64-encoder-online.waraxe.us/"
client.println(""); // encoded username
client.println(""); //This line is password
client.println("MAIL FROM:from@gmail.com");
client.println("RCPT TO:to@gmail.com");
client.println("DATA");
client.println("from:from@gmail.com");
client.println("to:to@gmail.com");
client.println("SUBJECT: Testing subject to arduino ethernet shield");
client.println();
client.println("This is the line body.");
client.println("This is another line of the body.");
client.println(".");
client.println(".");
client.println("QUIT");
} 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( ;; )
;
}
}