SMS WORKING
Dependencies: EthernetInterface NTPClient SimpleSMTPClient TextLCD mbed-rtos mbed
Fork of Application-SimpleSMTPClient_HelloWorld by
main.cpp
00001 // -- SimpleSMTPClient_HelloWorld.cpp -- 00002 // Used EthernetInterface Library 00003 // Don't support TSL/SSL. 00004 #include "mbed.h" 00005 #include "EthernetInterface.h" 00006 #include "NTPClient.h" 00007 #include "SimpleSMTPClient.h" 00008 #include "TextLCD.h" 00009 00010 #define DOMAIN "comcast.net" //gmail.com 00011 #define SERVER "smtp.comcast.net" //smtp.gmail.com 00012 #define PORT "587" //25 or 587,465(OutBound Port25 Blocking ) 465 00013 #define USER "patkionkar" //bhakti.kulkarni08 00014 #define PWD "book#jungle" //bhakti0887 00015 #define FROM_ADDRESS "patkionkar@comcast.net" //bhakti.kulkarni08 00016 // TO_ADDRESS (Of some address is possible.) 00017 // to-user1@domain, to-user2@domain, to-user3@domain .... 00018 // The TO_ADDRESS are less than 128 characters. 00019 #define TO_ADDRESS "patkionkar@comcast.net" 00020 00021 #define SUBJECT "Test Mail" 00022 00023 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00024 00025 int main() 00026 { 00027 EthernetInterface eth; 00028 char strTimeMsg[16]; 00029 lcd.cls(); 00030 printf("\n\n/* SimpleMTPClient library demonstration */\n"); 00031 00032 printf("Setting up ...\n"); 00033 eth.init(); 00034 eth.connect(); 00035 printf("Connected OK\n"); 00036 00037 // IP Address 00038 printf("IP Address is %s\n", eth.getIPAddress()); 00039 lcd.locate(0,1); 00040 lcd.printf("%s", eth.getIPAddress()); 00041 00042 // NTP Client 00043 printf("NTP setTime...\n"); 00044 NTPClient ntp; 00045 ntp.setTime("pool.ntp.org"); 00046 00047 time_t ctTime = time(NULL)+32400; // JST 00048 printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); 00049 strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); 00050 00051 lcd.locate(0,0); 00052 lcd.printf("[%s]",strTimeMsg); 00053 00054 00055 SimpleSMTPClient smtp; 00056 int ret; 00057 char msg[]="Hello SimpleSMTPClient "; 00058 00059 smtp.setFromAddress(FROM_ADDRESS); 00060 smtp.setToAddress(TO_ADDRESS); 00061 smtp.setMessage(SUBJECT,msg); 00062 smtp.addMessage("TEST TEST TEST\r\n"); 00063 00064 ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_PLAIN); 00065 printf("return value: %d\r\n",ret); 00066 00067 if (ret) { 00068 printf("E-mail Transmission Error\r\n"); 00069 } else { 00070 printf("E-mail Transmission OK\r\n"); 00071 } 00072 00073 // 00074 // send as SMS text 00075 // 00076 00077 smtp.setFromAddress(FROM_ADDRESS); 00078 smtp.setToAddress("4086851676@txt.att.net"); // MODIFY for carrier 00079 smtp.setMessage(SUBJECT,msg); 00080 smtp.addMessage("TEST TEST TEST\r\n"); 00081 00082 ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_PLAIN); 00083 00084 if (ret) { 00085 printf("SMS Transmission Error\r\n"); 00086 } else { 00087 printf("SMS Transmission OK\r\n"); 00088 } 00089 00090 return 0; 00091 00092 }
Generated on Fri Jul 22 2022 08:07:06 by 1.7.2