email sender via esp8266 and arduino  - Page 1
Forum section: electronics / projects

author: hussamaldean
author_rank: Unknown
timestamp: February 14, 2018, 04:08:32 pm
content: Hi allI want to send an email from gmail using esp8266 wifi module and arduino megaI managed to make the sketch of arduino to connect to wifi but I can't send emailhere you can find the codeCode:#include <LiquidCrystal_PCF8574.h>LiquidCrystal_PCF8574 lcd(0x27);boolean No_IP=false;String IP="";void check4IP(int t1){int t2=millis();Serial1.flush();while(t2+t1>millis()){while(Serial1.available()>0){if(Serial1.find("WIFI GOT IP")){No_IP=true;}}}}void get_ip(){//lcd.setCursor(0,0); lcd.clear();IP="";char ch=0;while(1){Serial1.println(F("AT+CIFSR"));while(Serial1.available()>0){if(Serial1.find("STAIP,")){delay(1000);Serial.print("IP Address:");while(Serial1.available()>0){ch=Serial1.read();if(ch=='+')break;IP+=ch;}}if(ch=='+')break;}if(ch=='+')break;delay(1000);}Serial.print(IP);Serial.print("Port:");Serial.println(80);}void connect_wifi(String cmd, int t){int temp=0,i=0;while(1){Serial1.println(cmd);while(Serial1.available()){if(Serial1.find("OK"))i=8;}delay(t);if(i>5)break;i++;}if(i==8)Serial.println("OK");elseSerial.println("Error");}void setup(){Serial1.begin(115200);lcd.setBacklight(255);Serial.begin(9600);lcd.begin(20,4);lcd.print("Sending Email by");lcd.setCursor(0,1);lcd.print(" Arduino & WIFI ");//delay(100);lcd.clear();lcd.print(" hussam ");//delay(100);lcd.clear();lcd.print("Finding ESP8266");//Serial1.println(F("AT"));//Serial1.println(F("ATE1"));connect_wifi(F("AT"),10);connect_wifi(F("ATE1"),10);//Serial1.println(F("AT+CWMODE=3"));connect_wifi("AT+CWMODE=3",10);lcd.clear();lcd.print("Connected");delay(100);//Serial1.println(F("AT+CWMODE=3"));connect_wifi("AT+CWMODE=3",10);Serial1.println("AT+CWQAP");Serial1.println("AT+RST");lcd.clear();lcd.print("Connecting WiFi");check4IP(5000);if(!No_IP){Serial.println("Connecting Wifi....");Serial1.println(F("AT+CWJAP=\"Hamoky.Net(AMER)\",\"ameer1986\"")); //provide your WiFi username and password here}else{}lcd.clear();lcd.print("WIFI Connected...");Serial.println("Wifi Connected");delay(1000);lcd.clear();lcd.print("Getting IP Add.");Serial.println("Getting IP Address....");get_ip();delay(1000);lcd.clear();lcd.print("IP:");lcd.print(IP);lcd.setCursor(0,1);lcd.print("PORT: 80");connect_wifi("AT+CIPMUX=1",100);connect_wifi("AT+CIPSERVER=1,80",100);delay(100);lcd.clear();lcd.print("Configuring Email..");Serial1.println("AT+CIPSTART=4,TCP,smtp.gmail.com,465");delay(100);//Serial1.println("AT+CIPSEND=4,20");//delay(100);Serial1.println("EHLO 1.2.3.4");delay(100);//Serial1.println("AT+CIPSEND=4,12");delay(100);lcd.clear();lcd.print("Try To Login.....");Serial1.println("AUTH LOGIN");delay(100);//Serial1.println(F("AT+CIPSEND=4,30"));delay(100);Serial1.println("your account"); //base64 encoded usernamedelay(100);//Serial1.println(F("AT+CIPSEND=4,18"));delay(100);Serial1.println("your pass"); //base64 encoded passwordlcd.clear();//lcd.print("Login Success");//delay(100);//Serial1.println("AT+CIPSEND=4,34");delay(100);Serial1.println("MAIL From:<hussamaldean@gmail.com>"); // use your email addressdelay(100);//Serial1.println("AT+CIPSEND=4,32");delay(100);lcd.clear();lcd.print("Sending Email");lcd.setCursor(0,1);lcd.print("hussamaldean@gmail.com");Serial1.println("RCPT TO:<hussamaldean@gmail.com>");//delay(100);//Serial1.println("AT+CIPSEND=4,6");delay(100);Serial1.println("DATA");//delay(100);//Serial1.println("AT+CIPSEND=4,24");delay(100);Serial1.println("Testing Success");delay(100);//Serial1.println("AT+CIPSEND=4,3");delay(100);Serial1.println('.');delay(100);Serial1.println("AT+CIPSEND=4,6");delay(100);Serial1.println("QUIT");delay(100);lcd.clear();lcd.print("Email Sent...");}void loop(){}but the email doesn't send at allis there any solution ?Regards