Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SimpleSMTPClient_HelloWorld USBHost-MSD_Sensors_1 IOT-GPS-SMS IOT_HW_5_websockets ... more
Revision 8:311b1f7cebb7, committed 2015-12-01
- Comitter:
- sunifu
- Date:
- Tue Dec 01 13:45:11 2015 +0000
- Parent:
- 7:0847fa2294a0
- Commit message:
- Update
Changed in this revision
| SimpleSMTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SimpleSMTPClient.cpp Sun Apr 13 07:39:38 2014 +0000
+++ b/SimpleSMTPClient.cpp Tue Dec 01 13:45:11 2015 +0000
@@ -3,6 +3,7 @@
* mbed Simple SMTP Client
* Copyright (c) 2012 Tadao Iida
* Released under the MIT License: http://mbed.org/license/mit
+ * 2015/12/1 Ver 1.5 Update
*/
//Debug is disabled by default
@@ -80,6 +81,7 @@
int ret = -1;
char ehlo[128];
+ char tmp1[256];
smtp.set_blocking(false, 1500);
smtp.connect(host, atoi(port)) ;
@@ -96,10 +98,7 @@
DBG("SEND %s(%d)", ehlo,strlen(ehlo));
#endif
smtp.send(ehlo, strlen(ehlo));
- if (receiveMessage(250)){
- smtp.close();
- return -1;
- }
+ if (receiveMessage(250)) goto exit;
if ( auth == SMTP_AUTH_PLAIN ){
if ( user && pwd ) {
@@ -109,9 +108,8 @@
snprintf(tmp, sizeof(tmp), "%s%c%s%c%s",user, 0, user, 0, pwd);
len = strlen(user)*2 + strlen(pwd) + 2;
base64enc(tmp, len, buf, sizeof(buf));
- smtp.send("AUTH PLAIN ", 11);
- smtp.send(buf, strlen(buf));
- smtp.send("\r\n", 2);
+ sprintf(tmp1,"AUTH PLAIN %s\r\n",buf);
+ smtp.send(tmp1, strlen(tmp1));
#ifdef __DEBUG__
DBG("base64[%s]\r\n", buf);
#endif
@@ -126,14 +124,11 @@
char tmp[80], buf[100];
int len;
- smtp.send("AUTH LOGIN ", 11);
- smtp.send("\r\n", 2);
-
snprintf(tmp, sizeof(tmp), "%s",user);
len = strlen(user) ;
base64enc(tmp, len, buf, sizeof(buf));
- smtp.send(buf, strlen(buf));
- smtp.send("\r\n", 2);
+ sprintf(tmp1,"AUTH LOGIN %s\r\n",buf);
+ smtp.send(tmp1, strlen(tmp1));
snprintf(tmp, sizeof(tmp), "%s",pwd);
len = strlen(pwd) ;
@@ -150,16 +145,14 @@
}
}
}
-
- smtp.send("MAIL FROM:<", 11);
- smtp.send(getFromAddress(), strlen(getFromAddress()));
- smtp.send(">\r\n", 3);
- if (receiveMessage(250)) {
- smtp.close();
- return -1;
- }
+
+ #ifdef __DEBUG__
+ DBG("FromAddress[%s]\r\n", getFromAddress());
+ #endif
+ sprintf(tmp1,"MAIL FROM:<%s>\r\n",getFromAddress());
+ smtp.send(tmp1, strlen(tmp1));
+ if (receiveMessage(250)) goto exit;
-
char tmp[128],addr[128];
int i = 0;
strcpy(tmp,getToAddress());
@@ -179,12 +172,12 @@
DBG("ToAddress[%s]\r\n", addr);
#endif
- smtp.send("RCPT TO: <", 10);
- smtp.send(addr, strlen(addr));
- smtp.send(">\r\n", 3);
+ sprintf(tmp1,"RCPT TO:<%s>\r\n",addr);
+ smtp.send(tmp1, strlen(tmp1));
+ if (receiveMessage(250)) goto exit;
+
if(tmp[i]==',') i++;
- if (receiveMessage(250)) goto exit;
}
ret = makeHeader();
if ( ret == -1 ) {
@@ -195,20 +188,18 @@
// mail Body
smtp.send("DATA\r\n", 6);
if (receiveMessage(354)) goto exit;
-
- smtp.send(getHeader(), strlen(getHeader()));
- smtp.send(getMessage(), strlen(getMessage()));
- smtp.send("\r\n.\r\n", 5);
+ sprintf(tmp1,"%s %s \r\n.\r\n",getHeader(),getMessage());
+ smtp.send(tmp1, strlen(tmp1));
if (receiveMessage(250)) goto exit;
#ifdef __DEBUG__
DBG("Header %s\r\n", getHeader());
DBG("Message %s\r\n", getMessage());
#endif
-
- ret = 0;
smtp.send("QUIT\r\n", 6);
if (receiveMessage(221)) goto exit;
+
+ ret = 0;
exit:
smtp.close();