Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
smtp.h
00001 #ifndef LWIP_HDR_APPS_SMTP_H 00002 #define LWIP_HDR_APPS_SMTP_H 00003 00004 #ifdef __cplusplus 00005 extern "C" { 00006 #endif 00007 00008 #include "lwip/apps/smtp_opts.h" 00009 #include "lwip/err.h" 00010 #include "lwip/prot/iana.h" 00011 00012 /** The default TCP port used for SMTP */ 00013 #define SMTP_DEFAULT_PORT LWIP_IANA_PORT_SMTP 00014 /** The default TCP port used for SMTPS */ 00015 #define SMTPS_DEFAULT_PORT LWIP_IANA_PORT_SMTPS 00016 00017 /** Email successfully sent */ 00018 #define SMTP_RESULT_OK 0 00019 /** Unknown error */ 00020 #define SMTP_RESULT_ERR_UNKNOWN 1 00021 /** Connection to server failed */ 00022 #define SMTP_RESULT_ERR_CONNECT 2 00023 /** Failed to resolve server hostname */ 00024 #define SMTP_RESULT_ERR_HOSTNAME 3 00025 /** Connection unexpectedly closed by remote server */ 00026 #define SMTP_RESULT_ERR_CLOSED 4 00027 /** Connection timed out (server didn't respond in time) */ 00028 #define SMTP_RESULT_ERR_TIMEOUT 5 00029 /** Server responded with an unknown response code */ 00030 #define SMTP_RESULT_ERR_SVR_RESP 6 00031 /** Out of resources locally */ 00032 #define SMTP_RESULT_ERR_MEM 7 00033 00034 /** Prototype of an smtp callback function 00035 * 00036 * @param arg argument specified when initiating the email 00037 * @param smtp_result result of the mail transfer (see defines SMTP_RESULT_*) 00038 * @param srv_err if aborted by the server, this contains the error code received 00039 * @param err an error returned by internal lwip functions, can help to specify 00040 * the source of the error but must not necessarily be != ERR_OK 00041 */ 00042 typedef void (*smtp_result_fn)(void *arg, u8_t smtp_result, u16_t srv_err, err_t err); 00043 00044 /** This structure is used as argument for smtp_send_mail_int(), 00045 * which in turn can be used with tcpip_callback() to send mail 00046 * from interrupt context, e.g. like this: 00047 * struct smtp_send_request *req; (to be filled) 00048 * tcpip_try_callback(smtp_send_mail_int, (void*)req); 00049 * 00050 * For member description, see parameter description of smtp_send_mail(). 00051 * When using with tcpip_callback, this structure has to stay allocated 00052 * (e.g. using mem_malloc/mem_free) until its 'callback_fn' is called. 00053 */ 00054 struct smtp_send_request { 00055 const char *from; 00056 const char* to; 00057 const char* subject; 00058 const char* body; 00059 smtp_result_fn callback_fn; 00060 void* callback_arg; 00061 /** If this is != 0, data is *not* copied into an extra buffer 00062 * but used from the pointers supplied in this struct. 00063 * This means less memory usage, but data must stay untouched until 00064 * the callback function is called. */ 00065 u8_t static_data; 00066 }; 00067 00068 00069 #if SMTP_BODYDH 00070 00071 #ifndef SMTP_BODYDH_BUFFER_SIZE 00072 #define SMTP_BODYDH_BUFFER_SIZE 256 00073 #endif /* SMTP_BODYDH_BUFFER_SIZE */ 00074 00075 struct smtp_bodydh { 00076 u16_t state; 00077 u16_t length; /* Length of content in buffer */ 00078 char buffer[SMTP_BODYDH_BUFFER_SIZE]; /* buffer for generated content */ 00079 #ifdef SMTP_BODYDH_USER_SIZE 00080 u8_t user[SMTP_BODYDH_USER_SIZE]; 00081 #endif /* SMTP_BODYDH_USER_SIZE */ 00082 }; 00083 00084 enum bdh_retvals_e { 00085 BDH_DONE = 0, 00086 BDH_WORKING 00087 }; 00088 00089 /** Prototype of an smtp body callback function 00090 * It receives a struct smtp_bodydh, and a buffer to write data, 00091 * must return BDH_WORKING to be called again and BDH_DONE when 00092 * it has finished processing. This one tries to fill one TCP buffer with 00093 * data, your function will be repeatedly called until that happens; so if you 00094 * know you'll be taking too long to serve your request, pause once in a while 00095 * by writing length=0 to avoid hogging system resources 00096 * 00097 * @param arg argument specified when initiating the email 00098 * @param smtp_bodydh state handling + buffer structure 00099 */ 00100 typedef int (*smtp_bodycback_fn)(void *arg, struct smtp_bodydh *bodydh); 00101 00102 err_t smtp_send_mail_bodycback(const char *from, const char* to, const char* subject, 00103 smtp_bodycback_fn bodycback_fn, smtp_result_fn callback_fn, void* callback_arg); 00104 00105 #endif /* SMTP_BODYDH */ 00106 00107 00108 err_t smtp_set_server_addr(const char* server); 00109 void smtp_set_server_port(u16_t port); 00110 #if LWIP_ALTCP && LWIP_ALTCP_TLS 00111 struct altcp_tls_config; 00112 void smtp_set_tls_config(struct altcp_tls_config *tls_config); 00113 #endif 00114 err_t smtp_set_auth(const char* username, const char* pass); 00115 err_t smtp_send_mail(const char *from, const char* to, const char* subject, const char* body, 00116 smtp_result_fn callback_fn, void* callback_arg); 00117 err_t smtp_send_mail_static(const char *from, const char* to, const char* subject, const char* body, 00118 smtp_result_fn callback_fn, void* callback_arg); 00119 void smtp_send_mail_int(void *arg); 00120 #ifdef LWIP_DEBUG 00121 const char* smtp_result_str(u8_t smtp_result); 00122 #endif 00123 00124 #ifdef __cplusplus 00125 } 00126 #endif 00127 00128 #endif /* LWIP_HDR_APPS_SMTP_H */
Generated on Tue Jul 12 2022 13:54:50 by
