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 Tadao Iida

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.

Committer:
sunifu
Date:
Wed Dec 12 08:45:51 2012 +0000
Revision:
3:73b115345ad1
Parent:
1:24f200936579
Ver1.01 Update SimpleSMTPClient

Who changed what in which revision?

UserRevisionLine numberNew 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 3:73b115345ad1 10 #define DOMAIN "DOMAIN"
sunifu 0:f6b11a930311 11 #define SERVER "smtp.mailserver.domain"
sunifu 3:73b115345ad1 12 #define PORT "25" //25 or 587,465(OutBound Port25 Blocking )
sunifu 0:f6b11a930311 13 #define USER "user-id"
sunifu 0:f6b11a930311 14 #define PWD "password"
sunifu 1:24f200936579 15 #define FROM_ADDRESS "user-id@domain"
sunifu 0:f6b11a930311 16 // TO_ADDRESS (Of some address is possible.)
sunifu 0:f6b11a930311 17 // to-user1@domain, to-user2@domain, to-user3@domain ....
sunifu 0:f6b11a930311 18 // The TO_ADDRESS are less than 128 characters.
sunifu 0:f6b11a930311 19 #define TO_ADDRESS "to-user@domain"
sunifu 0:f6b11a930311 20
sunifu 0:f6b11a930311 21 #define SUBJECT "Test Mail"
sunifu 0:f6b11a930311 22
sunifu 0:f6b11a930311 23 TextLCD lcd(p24, p26, p27, p28, p29, p30);
sunifu 0:f6b11a930311 24
sunifu 0:f6b11a930311 25 int main()
sunifu 0:f6b11a930311 26 {
sunifu 0:f6b11a930311 27 EthernetInterface eth;
sunifu 0:f6b11a930311 28 char strTimeMsg[16];
sunifu 0:f6b11a930311 29 lcd.cls();
sunifu 0:f6b11a930311 30 printf("\n\n/* SimpleMTPClient library demonstration */\n");
sunifu 0:f6b11a930311 31
sunifu 0:f6b11a930311 32 printf("Setting up ...\n");
sunifu 0:f6b11a930311 33 eth.init();
sunifu 0:f6b11a930311 34 eth.connect();
sunifu 0:f6b11a930311 35 printf("Connected OK\n");
sunifu 0:f6b11a930311 36
sunifu 3:73b115345ad1 37 // IP Address
sunifu 3:73b115345ad1 38 printf("IP Address is %s\n", eth.getIPAddress());
sunifu 3:73b115345ad1 39 lcd.locate(0,1);
sunifu 3:73b115345ad1 40 lcd.printf("%s", eth.getIPAddress());
sunifu 3:73b115345ad1 41
sunifu 3:73b115345ad1 42 // NTP Client
sunifu 0:f6b11a930311 43 printf("NTP setTime...\n");
sunifu 0:f6b11a930311 44 NTPClient ntp;
sunifu 0:f6b11a930311 45 ntp.setTime("pool.ntp.org");
sunifu 0:f6b11a930311 46
sunifu 0:f6b11a930311 47 time_t ctTime = time(NULL)+32400; // JST
sunifu 0:f6b11a930311 48 printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime));
sunifu 0:f6b11a930311 49 strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime));
sunifu 0:f6b11a930311 50
sunifu 0:f6b11a930311 51 lcd.locate(0,0);
sunifu 0:f6b11a930311 52 lcd.printf("[%s]",strTimeMsg);
sunifu 0:f6b11a930311 53
sunifu 0:f6b11a930311 54
sunifu 0:f6b11a930311 55 SimpleSMTPClient smtp;
sunifu 0:f6b11a930311 56 int ret;
sunifu 0:f6b11a930311 57 char msg[]="Hello SimpleSMTPClient ";
sunifu 0:f6b11a930311 58
sunifu 0:f6b11a930311 59 smtp.setFromAddress(FROM_ADDRESS);
sunifu 0:f6b11a930311 60 smtp.setToAddress(TO_ADDRESS);
sunifu 0:f6b11a930311 61 smtp.setMessage(SUBJECT,msg);
sunifu 0:f6b11a930311 62 smtp.addMessage("TEST TEST TEST\r\n");
sunifu 3:73b115345ad1 63
sunifu 3:73b115345ad1 64 ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_NONE);
sunifu 0:f6b11a930311 65
sunifu 0:f6b11a930311 66 if (ret) {
sunifu 0:f6b11a930311 67 printf("E-mail Transmission Error\r\n");
sunifu 0:f6b11a930311 68 } else {
sunifu 0:f6b11a930311 69 printf("E-mail Transmission OK\r\n");
sunifu 0:f6b11a930311 70 }
sunifu 0:f6b11a930311 71
sunifu 0:f6b11a930311 72 return 0;
sunifu 0:f6b11a930311 73
sunifu 0:f6b11a930311 74 }