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:
2:27053679f44b
Parent:
1:58550f022776
Child:
4:7d16b08a1291
--- a/SimpleSMTPClient.cpp	Tue Dec 04 09:55:36 2012 +0000
+++ b/SimpleSMTPClient.cpp	Wed Dec 12 08:37:19 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;
@@ -264,9 +269,4 @@
     if ( strlen(header) > 256 )
         return -1;
     return 0;
-}
-
-void SimpleSMTPClient::clearMessage(void)
-{
-    memset(message, 0, sizeof(message)); 
 }
\ No newline at end of file