EthernetInterface Libraryを使ったSimpleな SMTP ClientLibraryです. LOGIN認証を追加しました.(2014.4 Update) It is SMTPClient Library which is Simple using EthernetInterface Library.

Dependents:   SimpleSMTPClient_HelloWorld USBHost-MSD_Sensors_1 IOT-GPS-SMS IOT_HW_5_websockets ... more

Revision:
3:67a97516c315
Parent:
0:3ea21ce21fe1
--- a/SimpleSMTPClient.cpp	Mon Dec 03 09:55:59 2012 +0000
+++ b/SimpleSMTPClient.cpp	Wed Dec 12 08:24:35 2012 +0000
@@ -10,7 +10,7 @@
 //Enable debug
 #define __DEBUG__
 #include <cstdio>
-#define DBG(x, ...) std::printf("[NTPClient : DBG]"x"\r\n", ##__VA_ARGS__); 
+#define DBG(x, ...) std::printf("[DBG]"x"\r\n", ##__VA_ARGS__); 
 
 #else
 //Disable debug
@@ -76,9 +76,10 @@
     return 0;
 }
  
-int SimpleSMTPClient::sendmail (char *host, char *user, char *pwd, char *port,SMTPAuth auth) {
+int SimpleSMTPClient::sendmail (char *host, char *user, char *pwd, char *domain,char *port,SMTPAuth auth) {
 
     int ret = -1;
+    char ehlo[128];
  
     smtp.set_blocking(false, 1500); 
     smtp.connect(host, atoi(port)) ;
@@ -90,7 +91,11 @@
     
     // send request
     wait_ms(100);
-    smtp.send("EHLO mbed\r\n", 11);
+    sprintf(ehlo,"EHLO %s\r\n",domain);
+    #ifdef __DEBUG__
+        DBG("SEND %s(%d)", ehlo,strlen(ehlo));
+    #endif    
+    smtp.send(ehlo, strlen(ehlo));
     if (receiveMessage(250)){
         smtp.close();
         return -1;
@@ -117,9 +122,9 @@
         }
     }        
 
-    smtp.send("MAIL FROM: ", 11);
+    smtp.send("MAIL FROM: <", 12);
     smtp.send(getFromAddress(), strlen(getFromAddress()));
-    smtp.send("\r\n", 2);
+    smtp.send(">\r\n", 3);
     if (receiveMessage(250)) {
         smtp.close();
         return -1;
@@ -143,9 +148,9 @@
           DBG("ToAddress[%s]\r\n", addr);
         #endif
         
-        smtp.send("RCPT TO: ", 9);
+        smtp.send("RCPT TO: <", 10);
         smtp.send(addr, strlen(addr));
-        smtp.send("\r\n", 2);
+        smtp.send(">\r\n", 3);
         if(tmp[i]==',') i++;
         
         if (receiveMessage(250)) goto exit;