EthernetInterface Libraryを使ったSimpleな SMTP Clientプログラムを作成してみました。 I made the SMTP Client program that was Simple using EthernetInterface Library.
Dependencies: EthernetInterface NTPClient SimpleSMTPClient TextLCD mbed-rtos mbed
Fork of 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 "DOMAIN" 00011 #define SERVER "smtp.mailserver.domain" 00012 #define PORT "25" //25 or 587,465(OutBound Port25 Blocking ) 00013 #define USER "user-id" 00014 #define PWD "password" 00015 #define FROM_ADDRESS "user-id@domain" 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 "to-user@domain" 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_NONE); 00065 00066 if (ret) { 00067 printf("E-mail Transmission Error\r\n"); 00068 } else { 00069 printf("E-mail Transmission OK\r\n"); 00070 } 00071 00072 return 0; 00073 00074 }
Generated on Wed Jul 13 2022 05:38:44 by 1.7.2