Hello guys i'm trying to send an email using the arduino shield and i'm really having a hard time could you guys help me out thanks
#include <WiFi.h>
#include <SPI.h>
char ssid[] = "networkname"; // your network SSID (name)
char key[] = "networkey"; // your network key
int keyIndex = 1; // your network key Index number
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client; // Wifi client instead of Ethernet
IPAddress server(103,47,204,4); // smtp2go.com
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid,keyIndex,key);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
}
void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
// Check for serial input
byte inChar;
inChar = Serial.read();
if (inChar == 'e')
{
if(sendEmail()) {
Serial.println("Email sent");
}
else {
Serial.println("Email failed");
}
}
}
// Andy's code
byte sendEmail() {
byte thisByte = 0;
byte respCode;
if (client.connect(server,2525)) {
Serial.println("connected");
} else {
Serial.println("connection failed");
return 0;
}
if(!eRcv()) return 0;
// EHLO
client.println(F("EHLO 1.2.3.4\r\n")); //Public ip
if(!eRcv()) return 0;
client.print("AUTH LOGIN\r\n");
if(!eRcv()) return 0;
client.print("**************==\r\n");//username
if(!eRcv()) return 0;
client.print("*********\r\n");//password
if(!eRcv()) return 0;
// change this
client.print("MAIL From: <you@live.ca>\r\n");
if(!eRcv()) return 0;
// change this
client.print("RCPT To: <me@live.ca>\r\n");
if(!eRcv()) return 0;
client.print("DATA\r\n");
if(!eRcv()) return 0;
//change this
client.print("To: You <you@live.ca>\r\n");
// change this
client.print("From: Me <me@live.ca>\r\n");
client.print("Subject: Arduino email test\r\n");
client.print("Suck it\r\n");
client.print(".\r\n");
if(!eRcv()) return 0;
client.print("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");
}
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
Serial.print(bssid[5],HEX);
Serial.print(":");
Serial.print(bssid[4],HEX);
Serial.print(":");
Serial.print(bssid[3],HEX);
Serial.print(":");
Serial.print(bssid[2],HEX);
Serial.print(":");
Serial.print(bssid[1],HEX);
Serial.print(":");
Serial.println(bssid[0],HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption,HEX);
Serial.println();
}