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
Simple SMTP Client
Used EthernetInterface Library
Don't support TSL/SSL.
Import librarySimpleSMTPClient
EthernetInterface Libraryを使ったSimpleな SMTP ClientLibraryです. LOGIN認証を追加しました.(2014.4 Update) It is SMTPClient Library which is Simple using EthernetInterface Library.
Import programSimpleSMTPClient_HelloWorld
EthernetInterface Libraryを使ったSimpleな SMTP Clientプログラムを作成してみました。 I made the SMTP Client program that was Simple using EthernetInterface Library.
main.cpp@1:24f200936579, 2012-12-03 (annotated)
- Committer:
- sunifu
- Date:
- Mon Dec 03 09:59:24 2012 +0000
- Revision:
- 1:24f200936579
- Parent:
- 0:f6b11a930311
- Child:
- 3:73b115345ad1
Ver1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:f6b11a930311 | 1 | // -- SimpleSMTPClient_HelloWorld.cpp -- |
sunifu | 0:f6b11a930311 | 2 | // Used EthernetInterface Library |
sunifu | 0:f6b11a930311 | 3 | // Don't support TSL/SSL. |
sunifu | 0:f6b11a930311 | 4 | #include "mbed.h" |
sunifu | 0:f6b11a930311 | 5 | #include "EthernetInterface.h" |
sunifu | 0:f6b11a930311 | 6 | #include "NTPClient.h" |
sunifu | 0:f6b11a930311 | 7 | #include "SimpleSMTPClient.h" |
sunifu | 0:f6b11a930311 | 8 | #include "TextLCD.h" |
sunifu | 0:f6b11a930311 | 9 | |
sunifu | 0:f6b11a930311 | 10 | #define SERVER "smtp.mailserver.domain" |
sunifu | 0:f6b11a930311 | 11 | #define PORT "587" //25 or 587(OutBound Port25 Blocking ) |
sunifu | 0:f6b11a930311 | 12 | #define USER "user-id" |
sunifu | 0:f6b11a930311 | 13 | #define PWD "password" |
sunifu | 1:24f200936579 | 14 | #define FROM_ADDRESS "user-id@domain" |
sunifu | 0:f6b11a930311 | 15 | // TO_ADDRESS (Of some address is possible.) |
sunifu | 0:f6b11a930311 | 16 | // to-user1@domain, to-user2@domain, to-user3@domain .... |
sunifu | 0:f6b11a930311 | 17 | // The TO_ADDRESS are less than 128 characters. |
sunifu | 0:f6b11a930311 | 18 | #define TO_ADDRESS "to-user@domain" |
sunifu | 0:f6b11a930311 | 19 | |
sunifu | 0:f6b11a930311 | 20 | #define SUBJECT "Test Mail" |
sunifu | 0:f6b11a930311 | 21 | |
sunifu | 0:f6b11a930311 | 22 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
sunifu | 0:f6b11a930311 | 23 | |
sunifu | 0:f6b11a930311 | 24 | int main() |
sunifu | 0:f6b11a930311 | 25 | { |
sunifu | 0:f6b11a930311 | 26 | EthernetInterface eth; |
sunifu | 0:f6b11a930311 | 27 | char strTimeMsg[16]; |
sunifu | 0:f6b11a930311 | 28 | lcd.cls(); |
sunifu | 0:f6b11a930311 | 29 | printf("\n\n/* SimpleMTPClient library demonstration */\n"); |
sunifu | 0:f6b11a930311 | 30 | |
sunifu | 0:f6b11a930311 | 31 | printf("Setting up ...\n"); |
sunifu | 0:f6b11a930311 | 32 | eth.init(); |
sunifu | 0:f6b11a930311 | 33 | eth.connect(); |
sunifu | 0:f6b11a930311 | 34 | |
sunifu | 0:f6b11a930311 | 35 | printf("Connected OK\n"); |
sunifu | 0:f6b11a930311 | 36 | |
sunifu | 0:f6b11a930311 | 37 | printf("NTP setTime...\n"); |
sunifu | 0:f6b11a930311 | 38 | NTPClient ntp; |
sunifu | 0:f6b11a930311 | 39 | ntp.setTime("pool.ntp.org"); |
sunifu | 0:f6b11a930311 | 40 | |
sunifu | 0:f6b11a930311 | 41 | time_t ctTime = time(NULL)+32400; // JST |
sunifu | 0:f6b11a930311 | 42 | printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); |
sunifu | 0:f6b11a930311 | 43 | strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); |
sunifu | 0:f6b11a930311 | 44 | |
sunifu | 0:f6b11a930311 | 45 | lcd.locate(0,0); |
sunifu | 0:f6b11a930311 | 46 | lcd.printf("[%s]",strTimeMsg); |
sunifu | 0:f6b11a930311 | 47 | |
sunifu | 0:f6b11a930311 | 48 | // IP Address |
sunifu | 0:f6b11a930311 | 49 | printf("IP Address is %s\n", eth.getIPAddress()); |
sunifu | 0:f6b11a930311 | 50 | lcd.locate(0,1); |
sunifu | 0:f6b11a930311 | 51 | lcd.printf("%s", eth.getIPAddress()); |
sunifu | 0:f6b11a930311 | 52 | |
sunifu | 0:f6b11a930311 | 53 | SimpleSMTPClient smtp; |
sunifu | 0:f6b11a930311 | 54 | int ret; |
sunifu | 0:f6b11a930311 | 55 | char msg[]="Hello SimpleSMTPClient "; |
sunifu | 0:f6b11a930311 | 56 | |
sunifu | 0:f6b11a930311 | 57 | smtp.setFromAddress(FROM_ADDRESS); |
sunifu | 0:f6b11a930311 | 58 | smtp.setToAddress(TO_ADDRESS); |
sunifu | 0:f6b11a930311 | 59 | smtp.setMessage(SUBJECT,msg); |
sunifu | 0:f6b11a930311 | 60 | smtp.addMessage("TEST TEST TEST\r\n"); |
sunifu | 0:f6b11a930311 | 61 | |
sunifu | 0:f6b11a930311 | 62 | ret = smtp.sendmail(SERVER, USER, PWD, PORT,SMTP_AUTH_PLAIN); |
sunifu | 0:f6b11a930311 | 63 | |
sunifu | 0:f6b11a930311 | 64 | if (ret) { |
sunifu | 0:f6b11a930311 | 65 | printf("E-mail Transmission Error\r\n"); |
sunifu | 0:f6b11a930311 | 66 | } else { |
sunifu | 0:f6b11a930311 | 67 | printf("E-mail Transmission OK\r\n"); |
sunifu | 0:f6b11a930311 | 68 | } |
sunifu | 0:f6b11a930311 | 69 | |
sunifu | 0:f6b11a930311 | 70 | return 0; |
sunifu | 0:f6b11a930311 | 71 | |
sunifu | 0:f6b11a930311 | 72 | } |