gs fan
/
GSwifi_smtp
SMTP client (send mail) GSwifi see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Diff: main.cpp
- Revision:
- 0:50f63fa8a396
- Child:
- 1:8a46a714f75d
diff -r 000000000000 -r 50f63fa8a396 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 01 02:58:48 2012 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" +#include "GSwifi.h" +#include "GSwifi_net.h" + +#define SERVER "mail.example.com" +#define PORT 587 // 25 +#define TO "to@example.com" +#define FROM "from@example.com" +#define SUBJECT "TEST" +#define MESG "Hello!\r\n" +#define USER "username" // SMTP Auth +#define PWD "password" // SMTP Auth + +#define SECURE GSSEC_WPA_PSK +#define SSID "SSID" +#define PASS "passkey" + +GSwifi gs(p13, p14); // TX, RX (no flow control) +// GSwifi gs(p13, p14, p12, P0_22); // TX, RX, CTS, RTS + +Serial pc(USBTX, USBRX); +DigitalOut led1(LED1), led2(LED2); + +int main () { + IpAddr ipaddr, netmask, gateway, nameserver; + Host host; + + led1 = 1; + pc.baud(115200); + + pc.printf("connect\r\n"); + if (gs.connect(SECURE, SSID, PASS)) { + return -1; + } + gs.getAddress(ipaddr, netmask, gateway, nameserver); + pc.printf("ip %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); + + led2 = 1; + pc.printf("sendmail\r\n"); + host.setName(SERVER); + host.setPort(PORT); +// gs.mail(host, TO, FROM, SUBJECT, MESG); // no auth + gs.mail(host, TO, FROM, SUBJECT, MESG, USER, PWD); // SMTP auth + + for (;;) { + gs.poll(); + + wait_ms(50); + led1 = !led1; + led2 = 0; + } +}