Email for ESP8266 | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Email for ESP8266
No permission to create posts
June 8, 2015
11:52 pm
Avatar
tytower
New Member
Members
Forum Posts: 4
Member Since:
June 8, 2015
sp_UserOfflineSmall Offline

All the notes are in the code
[code]
//Adapted from SurferTim's Ethernet email program by Ty Tower May 2015
Register at smtp2go.com --easy. Encode user and password for smtp2go.com in base 64 utf8--go here "https://www.base64encode.org/".
Put those in the right places in code and change the IP details to yours
Put in where you want to send the email and who it is from.
Change the mac address to the one from your ESP8266 module
#include
//#include

const char* ssid = "----------HOME";
const char* password = "-------------";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
WiFiClient client;

// this must be unique put yours in here
byte mac[] = { 0x18, 0xFE, 0x34, 0xA1 ,0x5C, 0x44 }; //from ESP8266
// change network settings to yours
IPAddress ip( 192, 168, 0, 3 );
IPAddress gateway( 192, 168, 0, 1 );
IPAddress subnet( 255, 255, 255, 0 );
//IPAddress server(?,?,?,?); // numeric IP for smtpcorp.com (no DNS)
char smptcorp[] = "smtpcorp.com";
int port = 2525;

void setup()
{
Serial.begin(115200);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
server.begin();
delay(10000);
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()
{
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

byte thisByte = 0;
byte respCode;

if(client.connect( smtpcorp,port) == 1) {
Serial.println(F("connected smtp2go"));
} else {
Serial.println(F("connection failed smtp2go"));
return 0;
}
if(!eRcv()) {Serial.println("before ehlo");return 0 ;}

Serial.println(F("Sending ehlo"));
// replace 192.168.0.3 with your ESP8266's ip
client.println("EHLO 192.168.0.3");
if(!eRcv()) {Serial.println("ehlo");return 0 ;}

Serial.println(F("Sending auth login"));
client.println("auth login");
if(!eRcv()) {Serial.println("auth");return 0 ;}

Serial.println("Sending User");
// Change to your base64 encoded user
client.println("------------------------------------");//
if(!eRcv()) {Serial.println("user");return 0 ;}

Serial.println(F("Sending Password"));
// change to your base64 encoded password
client.println("----------------------------------");//

if(!eRcv()) {Serial.println("ehlo");return 0;}

// change to your email address (sender)
Serial.println(F("Sending From"));
client.println("MAIL From: ");
if(!eRcv()) {Serial.println("email");return 0 ;}

// change to recipient address
Serial.println(F("Sending To"));
client.println("RCPT To: ");
if(!eRcv()) {Serial.println("email");return 0 ;}

Serial.println(F("Sending DATA"));
client.println("DATA");
if(!eRcv()) {Serial.println("email");return 0 ;}

Serial.println(F("Sending email"));

// change to recipient address
client.println("To: Ty Tower ");

// change to your address
client.println("From: Weather ");

client.println("Subject: ESP8266 email test
");

client.println("This is from my ESP8266-12 Module 3!");

client.println(".");

if(!eRcv()) {Serial.println("aftersending");return 0 ;}

Serial.println(F("Sending QUIT")); //Serial.println(F("Sending QUIT"));
client.println("QUIT");

if(!eRcv()) {Serial.println("afterQuit");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("10 sec
Timeout"));
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("efail
Timeout"));
return;
}
}

while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}

client.stop();

Serial.println(F("disconnected"));
}
[/code]

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
18 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Team_mafia, icXu, emorphistechno, VTVMART, manimozhi, adamhebrew

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457