daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. const char* SSID = "SSID";
  3. const char* PASS = "pass";
  4. char server[] = "mail.smtpcorp.com";
  5.  
  6. WiFiClient client;
  7. void setup()
  8. {
  9.   Serial.begin(115200);
  10.   delay(10);
  11.   Serial.println("");
  12.   Serial.println("");
  13.   Serial.print("Connecting To ");
  14.   Serial.println(SSID);
  15.   WiFi.begin(SSID, PASS);
  16.  
  17.   while (WiFi.status() != WL_CONNECTED)
  18.   {
  19.     delay(500);
  20.     Serial.print(".");
  21.   }
  22.   Serial.println("");
  23.   Serial.println("WiFi Connected");
  24.   Serial.print("IP address: ");
  25.   Serial.println(WiFi.localIP());
  26.   byte ret = sendEmail();
  27. }
  28.  
  29. void loop()
  30. {
  31. }
  32.  
  33. byte sendEmail()
  34. {
  35.   byte thisByte = 0;
  36.   byte respCode;
  37.  
  38.   if (client.connect(server, 2525) == 1) {
  39.     Serial.println(F("connected"));
  40.   } else {
  41.     Serial.println(F("connection failed"));
  42.     return 0;
  43.   }
  44.   if (!eRcv()) return 0;
  45.  
  46.   Serial.println(F("Sending EHLO"));
  47.   client.println("EHLO www.example.com");
  48.   if (!eRcv()) return 0;
  49.   Serial.println(F("Sending auth login"));
  50.   client.println("auth login");
  51.   if (!eRcv()) return 0;
  52.   Serial.println(F("Sending User"));
  53.   // Change to your base64, ASCII encoded user
  54.   client.println("xxxxxx"); //<---------User
  55.   if (!eRcv()) return 0;
  56.   Serial.println(F("Sending Password"));
  57.   // change to your base64, ASCII encoded password
  58.   client.println("yyyyyyyy");//<---------Passw
  59.   if (!eRcv()) return 0;
  60.   Serial.println(F("Sending From"));
  61.   // change to your email address (sender)
  62.   client.println(F("MAIL From: cccc@gmail.com"));
  63.   if (!eRcv()) return 0;
  64.   // change to recipient address
  65.   Serial.println(F("Sending To"));
  66.   client.println(F("RCPT To: xxx@yormai.com"));
  67.   if (!eRcv()) return 0;
  68.   Serial.println(F("Sending DATA"));
  69.   client.println(F("DATA"));
  70.   if (!eRcv()) return 0;
  71.   Serial.println(F("Sending email"));
  72.   // change to recipient address
  73.   client.println(F("To:  xxx@yormai.com"));
  74.   // change to your address
  75.   client.println(F("From: yyyyy@gmail.com"));
  76.   client.println(F("Subject: Esp8266 email test\r\n"));
  77.   client.println(F("This is from my ESP8266\n"));
  78.   client.println(F("This is line 2 from my ESP8266"));
  79.   client.println(F("This is line 3 from my ESP8266"));
  80.  
  81.   client.println(F("."));
  82.   if (!eRcv()) return 0;
  83.   Serial.println(F("Sending QUIT"));
  84.   client.println(F("QUIT"));
  85.   if (!eRcv()) return 0;
  86.   client.stop();
  87.   Serial.println(F("disconnected"));
  88.   return 1;
  89. }
  90.  
  91. byte eRcv()
  92. {
  93.   byte respCode;
  94.   byte thisByte;
  95.   int loopCount = 0;
  96.  
  97.   while (!client.available()) {
  98.     delay(1);
  99.     loopCount++;
  100.     // if nothing received for 10 seconds, timeout
  101.     if (loopCount > 10000) {
  102.       client.stop();
  103.       Serial.println(F("\r\nTimeout"));
  104.       return 0;
  105.     }
  106.   }
  107.  
  108.   respCode = client.peek();
  109.   while (client.available())
  110.   {
  111.     thisByte = client.read();
  112.     Serial.write(thisByte);
  113.   }
  114.  
  115.   if (respCode >= '4')
  116.   {
  117.     //  efail();
  118.     return 0;
  119.   }
  120.   return 1;
  121. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top