SMS AND EMAIL WORKING
Dependents: Application-SimpleSMTPClient_HelloWorld final
Fork of SimpleSMTPClient by
SimpleSMTPClient.h@5:846af4db63c5, 2012-12-15 (annotated)
- Committer:
- sunifu
- Date:
- Sat Dec 15 14:11:50 2012 +0000
- Revision:
- 5:846af4db63c5
- Parent:
- 4:7d16b08a1291
- Child:
- 7:0847fa2294a0
Ver 1.04 Add msgLength Function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:3ea21ce21fe1 | 1 | /* |
sunifu | 0:3ea21ce21fe1 | 2 | * |
sunifu | 0:3ea21ce21fe1 | 3 | * mbed Simple SMTP Client |
sunifu | 0:3ea21ce21fe1 | 4 | * Copyright (c) 2012 Tadao Iida |
sunifu | 0:3ea21ce21fe1 | 5 | * Released under the MIT License: http://mbed.org/license/mit |
sunifu | 0:3ea21ce21fe1 | 6 | */ |
sunifu | 0:3ea21ce21fe1 | 7 | |
sunifu | 0:3ea21ce21fe1 | 8 | /** @file |
sunifu | 0:3ea21ce21fe1 | 9 | * @brief Simple SMTP Client |
sunifu | 0:3ea21ce21fe1 | 10 | */ |
sunifu | 0:3ea21ce21fe1 | 11 | |
sunifu | 0:3ea21ce21fe1 | 12 | #ifndef SimpleSMTPC_h |
sunifu | 0:3ea21ce21fe1 | 13 | #define SimpleSMTPC_h |
sunifu | 0:3ea21ce21fe1 | 14 | |
sunifu | 0:3ea21ce21fe1 | 15 | #include "EthernetInterface.h" |
sunifu | 0:3ea21ce21fe1 | 16 | |
sunifu | 0:3ea21ce21fe1 | 17 | ///SMTP authentication |
sunifu | 0:3ea21ce21fe1 | 18 | enum SMTPAuth { |
sunifu | 0:3ea21ce21fe1 | 19 | SMTP_AUTH_NONE, ///<No authentication |
sunifu | 0:3ea21ce21fe1 | 20 | SMTP_AUTH_PLAIN ///<AUTH PLAIN authentication |
sunifu | 0:3ea21ce21fe1 | 21 | }; |
sunifu | 0:3ea21ce21fe1 | 22 | |
sunifu | 0:3ea21ce21fe1 | 23 | ///SimpleSMTP client results |
sunifu | 0:3ea21ce21fe1 | 24 | enum SMTPResult |
sunifu | 0:3ea21ce21fe1 | 25 | { |
sunifu | 0:3ea21ce21fe1 | 26 | SMTP_AUTH_OK = 235, ///<Authentication successful |
sunifu | 0:3ea21ce21fe1 | 27 | SMTP_OK = 250, ///<Requested mail action okay, completed |
sunifu | 0:3ea21ce21fe1 | 28 | SMTP_INPUT = 354 ///<Start mail input |
sunifu | 0:3ea21ce21fe1 | 29 | }; |
sunifu | 0:3ea21ce21fe1 | 30 | #define DEBUG |
sunifu | 0:3ea21ce21fe1 | 31 | |
sunifu | 0:3ea21ce21fe1 | 32 | #define SMTP_TIMEOUT 15000 // ms |
sunifu | 0:3ea21ce21fe1 | 33 | |
sunifu | 0:3ea21ce21fe1 | 34 | class SimpleSMTPClient |
sunifu | 0:3ea21ce21fe1 | 35 | { |
sunifu | 0:3ea21ce21fe1 | 36 | public: |
sunifu | 0:3ea21ce21fe1 | 37 | /** |
sunifu | 0:3ea21ce21fe1 | 38 | Instantiate the SimpleSMTP client |
sunifu | 0:3ea21ce21fe1 | 39 | */ |
sunifu | 0:3ea21ce21fe1 | 40 | SimpleSMTPClient(); |
sunifu | 0:3ea21ce21fe1 | 41 | |
sunifu | 0:3ea21ce21fe1 | 42 | /** send mail |
sunifu | 0:3ea21ce21fe1 | 43 | * @param host mail server |
sunifu | 0:3ea21ce21fe1 | 44 | * @param data mail body |
sunifu | 0:3ea21ce21fe1 | 45 | * @param user auth username |
sunifu | 0:3ea21ce21fe1 | 46 | * @param pwd auth password |
sunifu | 2:27053679f44b | 47 | * @param domain |
sunifu | 0:3ea21ce21fe1 | 48 | * @param port mail port |
sunifu | 0:3ea21ce21fe1 | 49 | * @param auth SMTP auth |
sunifu | 0:3ea21ce21fe1 | 50 | * @return 0:success, -1:failue |
sunifu | 0:3ea21ce21fe1 | 51 | */ |
sunifu | 2:27053679f44b | 52 | int sendmail (char *host, char *user, char *pwd,char *domain,char *port,SMTPAuth auth); |
sunifu | 0:3ea21ce21fe1 | 53 | |
sunifu | 0:3ea21ce21fe1 | 54 | /** setMessage |
sunifu | 0:3ea21ce21fe1 | 55 | * @param sub Subject <The Subject are less than 64 characters.> |
sunifu | 0:3ea21ce21fe1 | 56 | * @param msg Message |
sunifu | 0:3ea21ce21fe1 | 57 | * @return 0:success, -1:failue |
sunifu | 0:3ea21ce21fe1 | 58 | */ |
sunifu | 0:3ea21ce21fe1 | 59 | int setMessage(char *sub,char *msg); |
sunifu | 0:3ea21ce21fe1 | 60 | |
sunifu | 0:3ea21ce21fe1 | 61 | /** addMessage |
sunifu | 0:3ea21ce21fe1 | 62 | * @param msg Message |
sunifu | 0:3ea21ce21fe1 | 63 | * @return 0:success, -1:failue |
sunifu | 0:3ea21ce21fe1 | 64 | */ |
sunifu | 0:3ea21ce21fe1 | 65 | int addMessage(char *msg); |
sunifu | 0:3ea21ce21fe1 | 66 | |
sunifu | 0:3ea21ce21fe1 | 67 | /** setFromAddress |
sunifu | 0:3ea21ce21fe1 | 68 | * @param from mail address |
sunifu | 0:3ea21ce21fe1 | 69 | * @return character count, -1:failue |
sunifu | 0:3ea21ce21fe1 | 70 | */ |
sunifu | 0:3ea21ce21fe1 | 71 | int setFromAddress(char *from); |
sunifu | 0:3ea21ce21fe1 | 72 | |
sunifu | 0:3ea21ce21fe1 | 73 | /** setToAddress <The ToAddress are less than 128 characters.> |
sunifu | 0:3ea21ce21fe1 | 74 | * @param to mail address |
sunifu | 0:3ea21ce21fe1 | 75 | * @return character count, -1:failue |
sunifu | 0:3ea21ce21fe1 | 76 | */ |
sunifu | 0:3ea21ce21fe1 | 77 | int setToAddress(char *to); |
sunifu | 0:3ea21ce21fe1 | 78 | |
sunifu | 4:7d16b08a1291 | 79 | /** clearMessage |
sunifu | 4:7d16b08a1291 | 80 | * |
sunifu | 4:7d16b08a1291 | 81 | */ |
sunifu | 4:7d16b08a1291 | 82 | void clearMessage(void); |
sunifu | 5:846af4db63c5 | 83 | |
sunifu | 5:846af4db63c5 | 84 | /** msgLength |
sunifu | 5:846af4db63c5 | 85 | * |
sunifu | 5:846af4db63c5 | 86 | */ |
sunifu | 5:846af4db63c5 | 87 | int msgLength(void); |
sunifu | 2:27053679f44b | 88 | |
sunifu | 0:3ea21ce21fe1 | 89 | |
sunifu | 0:3ea21ce21fe1 | 90 | private: |
sunifu | 0:3ea21ce21fe1 | 91 | int base64enc(const char *input, unsigned int length, char *output, int outputlen); |
sunifu | 0:3ea21ce21fe1 | 92 | int receiveMessage(int code); |
sunifu | 0:3ea21ce21fe1 | 93 | char* getFromAddress(void); |
sunifu | 0:3ea21ce21fe1 | 94 | char* getToAddress(void); |
sunifu | 0:3ea21ce21fe1 | 95 | char* getSubject(); |
sunifu | 0:3ea21ce21fe1 | 96 | char* getHeader(); |
sunifu | 0:3ea21ce21fe1 | 97 | char* getMessage(); |
sunifu | 0:3ea21ce21fe1 | 98 | int makeHeader(void); |
sunifu | 0:3ea21ce21fe1 | 99 | |
sunifu | 0:3ea21ce21fe1 | 100 | TCPSocketConnection smtp; |
sunifu | 0:3ea21ce21fe1 | 101 | char header[256]; |
sunifu | 0:3ea21ce21fe1 | 102 | char body[1500]; |
sunifu | 0:3ea21ce21fe1 | 103 | char from[64]; |
sunifu | 0:3ea21ce21fe1 | 104 | char to[128]; |
sunifu | 0:3ea21ce21fe1 | 105 | char subject[64]; |
sunifu | 0:3ea21ce21fe1 | 106 | char message[1244]; |
sunifu | 0:3ea21ce21fe1 | 107 | }; |
sunifu | 0:3ea21ce21fe1 | 108 | |
sunifu | 0:3ea21ce21fe1 | 109 | #endif |