Can anyone suggest a email library which will work on the ESP8266?
Can anyone suggest a email library which will work on the ESP8266?
Explore... Chat... Share...
Moderator: igrr
//Adapted from SurferTims EthernetEmail by Ty Tower
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const char* ssid = "---------";
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 for your module
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 Yahoo (no DNS)
char myserver[] = "smtp.mail.yahoo.com";
int port = 465;
void setup()
{
Serial.begin(115200);
pinMode(4,OUTPUT);
digitalWrite(4,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(myserver,port) == 1) {
Serial.println(F("connected"));
} else {
Serial.println(F("connection failed"));
return 0;
}
if(!eRcv()) {Serial.println("before ehlo");return 0 ;}
Serial.println(F("Sending hello"));
// replace 1.2.3.4 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: <ESP8266-3>");
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 <ESP8266-3>");
client.println("Subject: ESP8266 email test\r\n");
client.println("This is from my ESP8266-12 Module 3!");
client.println(".");
if(!eRcv()) return 0;
Serial.println(F("Sending QUIT")); //Serial.println(F("Sending QUIT"));
client.println("QUIT");
if(!eRcv()) 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 \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(F("QUIT"));
while(!client.available()) {
delay(1);
loopCount++;
// if nothing received for 10 seconds, timeout
if(loopCount > 10000) {
client.stop();
Serial.println(F("efail \r\nTimeout"));
return;
}
}
while(client.available())
{
thisByte = client.read();
Serial.write(thisByte);
}
client.stop();
Serial.println(F("disconnected"));
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]