Go Down

Topic: The error I received when sending an e-mail (Read 193 times) previous topic - next topic

muraterzioglu

Jan 11, 2018, 03:04 pm Last Edit: Jan 11, 2018, 03:35 pm by muraterzioglu
I want to send E-Mail with esp8266 and arduino mega but where do I enter the login information. the code below (like base64 username and pass)

Using Tuts: https://playground.arduino.cc/Code/WiFiEmailClient


Code: [Select]

#include <SPI.h>
#include <WiFi.h>

// Setup on a 128 bit WEP network, change to suit for WPA

char ssid[] = "KemalAtaturk";      //  your network SSID (name)
char pass[] = "baskomutan";   // your network password
int keyIndex = 1;    // your network key Index number (needed only for WEP)

IPAddress ip( 192, 168, 1, 223 );    // ipaddress obtained from access point
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );

char server[] = "smtp.gmail.com";  // smtp mail server  (mine.com)

int status = WL_IDLE_STATUS;

WiFiClient client;

void setup()
{
Serial.begin(9600);
pinMode(9,OUTPUT);          // changed to use onboard LED
digitalWrite(9,HIGH);
WiFi.begin(ssid, keyIndex, pass);
delay(2000);
Serial.println("Ready. Press 'e' to send.");
}

void loop()
{
  byte inChar;
  inChar = Serial.read();

 if(inChar == 'e')
  {
      if(sendEmail()) Serial.println("Email sent");   
      else Serial.println("Email failed");
  }     
}

byte sendEmail()
{
  byte thisByte = 0;
  byte respCode;

 if(client.connect(server,25)) {
    Serial.println("connected");
  } else {
    Serial.println("connection failed");
    return 0;
  }

 if(!eRcv()) return 0;
  Serial.println("Sending helo");

// change to your public ip
  client.write("helo 1.2.3.4\r\n");

 if(!eRcv()) return 0;
  Serial.println("Sending From");

// change to your email address (sender)
  client.write("MAIL From: <denekeposta@gmail.com>\r\n");

 if(!eRcv()) return 0;

// change to recipient address
  Serial.println("Sending To");
  client.write("RCPT To: <denekeposta@gmail.com>\r\n");

 if(!eRcv()) return 0;

 Serial.println("Sending DATA");
  client.write("DATA\r\n");

 if(!eRcv()) return 0;

 Serial.println("Sending email");

// change to recipient address
  client.write("To: You <denekeposta@gmail.com>\r\n");

// change to your address
  client.write("From: Me <denekeposta@gmail.com>\r\n");

 client.write("Subject: Arduino email test\r\n");
 client.write("This is from my Arduino WiFi shield!\r\n");
 client.write(".\r\n");

 if(!eRcv()) return 0;

 Serial.println("Sending QUIT");
 client.write("QUIT\r\n");

 if(!eRcv()) return 0;

 client.stop();

 Serial.println("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("\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.write("QUIT\r\n");

 while(!client.available()) {
   delay(1);
   loopCount++;

   // if nothing received for 10 seconds, timeout
   if(loopCount > 10000) {
     client.stop();
     Serial.println("\r\nTimeout");
     return;
   }
 }

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

 client.stop();

 Serial.println("disconnected");
}

SurferTim

Read the second example on that page. SMTP2GO requires a user/password.

Go Up