00001 /*! \file my_smtp.h 00002 Header file for the smtp.c 00003 */ 00004 00005 #ifdef __cplusplus 00006 extern "C" { 00007 #endif 00008 00009 #ifndef MY_SMTP_HEADER 00010 00011 #include "my_sockets.h" 00012 00013 /* ------------------------------------------------- */ 00014 /* Configuration values and data structures */ 00015 /* ------------------------------------------------- */ 00016 00017 /*! \brief Maximum number of characters for the client identification (HELO command). 00018 */ 00019 00020 #define SMTP_ID_SIZE 1034 00021 00022 /*! \brief Maximum number of characters for an e-mail address. 00023 */ 00024 00025 #define SMTP_EMAIL_SIZE_MAX 1024 00026 00027 /*! \brief Maximum number of recipients for a given mail. 00028 */ 00029 00030 #define SMTP_RCPT_MAX 128 00031 00032 /*! \brief This structure defines the information used by the SMTP client to send an e-mail. 00033 */ 00034 00035 struct smtp_mail { 00036 /*! \brief The e-mail address of the sender. */ 00037 char from[SMTP_EMAIL_SIZE_MAX]; 00038 00039 /*! \brief The e-mail addresses of the recipients. */ 00040 char rcpt[SMTP_RCPT_MAX][SMTP_EMAIL_SIZE_MAX]; 00041 00042 /*! \brief The number of recipients. */ 00043 int rcpt_number; 00044 00045 /*! \brief Mail body to be sent. This must point to a zero terminated string of 00046 characters. */ 00047 char *data; 00048 }; 00049 00050 /*! \brief Maximum number of characters for a host name. 00051 */ 00052 00053 #define SMTP_HOSTNAME_SIZE 512 00054 00055 /*! \brief This structure defines the information used by the SMTP client to connect to the server. 00056 */ 00057 00058 struct smtp_connexion_config { 00059 /*! \brief The client identification (HELO command). */ 00060 char id[SMTP_ID_SIZE]; 00061 00062 /*! \brief TCP port used to the server (default is 25). */ 00063 int port; 00064 00065 /*! \brief Host name of the server that runs the SMTP server. */ 00066 char host[SMTP_HOSTNAME_SIZE]; 00067 00068 /*! \brief Connexion timeout in seconds. */ 00069 long connect_timeout_sec; 00070 00071 /*! \brief Connexion timeout in micro seconds. */ 00072 long connect_timeout_micro; 00073 00074 /*! \brief Read timeout in seconds. */ 00075 long read_timeout_sec; 00076 00077 /*! \brief Read timeout in micro seconds. */ 00078 long read_timeout_micro; 00079 }; 00080 00081 /* ------------------------------------------------- */ 00082 /* Data structure used to store the status of an */ 00083 /* operation. */ 00084 /* ------------------------------------------------- */ 00085 00086 /*! \brief This structure defines the information returned by all client SMTP functions. 00087 */ 00088 00089 struct smtp_res { 00090 /*! \brief Error code. */ 00091 int error_code; 00092 00093 /*! \brief Ellapsed time in milli-seconds. */ 00094 long ellapsed; 00095 }; 00096 00097 /* ------------------------------------------------- */ 00098 /* Data structure used to store information about */ 00099 /* the answer of a SMTP server. */ 00100 /* ------------------------------------------------- */ 00101 00102 /*! \brief This structure contains the information included in the answer from a SMTP server. 00103 */ 00104 00105 struct smtp_response { 00106 /* Not used yet, but defined for future improvement */ 00107 }; 00108 00109 /* ------------------------------------------------- */ 00110 /* Library API */ 00111 /* ------------------------------------------------- */ 00112 00113 int client_smtp_connect ( 00114 struct smtp_connexion_config *conf, 00115 struct smtp_res *result 00116 ); 00117 00118 void smtp_disconnect(); 00119 00120 int smtp_send_email ( 00121 struct smtp_connexion_config *conf, 00122 struct smtp_mail *email, 00123 struct smtp_res *result 00124 ); 00125 00126 /* ------------------------------------------------- */ 00127 /* Error codes */ 00128 /* */ 00129 /* ### WARNING ### */ 00130 /* */ 00131 /* This library uses the library 'libmy_sockets.a'. */ 00132 /* The returned error codes for the SMTP library */ 00133 /* must be negative and lower that the lowest return */ 00134 /* value for the library 'libmy_sockets.a' (see file */ 00135 /* "my_sockets.h"). */ 00136 /* ------------------------------------------------- */ 00137 00138 /*! \brief Return balues for all the SMTP API. This means that the system call write() failed. 00139 */ 00140 00141 #define SMTP_WRITE_ERROR -100 00142 00143 /*! \brief Return balues for all the SMTP API. This means that the response from the SMTP server was 00144 not valid. 00145 */ 00146 00147 #define SMTP_BAD_ANSWER -101 00148 00149 /*! \brief Return balues for the function smtp_send_email(). This means that one of the input arguments 00150 "from" or "rcpt" is too long. 00151 */ 00152 00153 #define SMTP_BUFFER_OVERFLOW -102 00154 00155 /* ------------------------------------------------- */ 00156 /* Internal buffer size used to receive/send data */ 00157 /* from/to the SMTP server. */ 00158 /* ------------------------------------------------- */ 00159 00160 /*! \brief Size of the buffer used to receive/send data from/to the SMTP server. 00161 */ 00162 00163 #define SMTP_BUFFER_SIZE 1024 00164 00165 /* ------------------------------------------------- */ 00166 /* SMTP status returned by the SMTP server */ 00167 /* ------------------------------------------------- */ 00168 00169 /*! \brief Return value for the function response_parser(). The SMTP server returned "220 ...". */ 00170 00171 #define SMTP_SERVER_IDENTIFICATION_OK 220 00172 00173 /*! \brief Return value for the function response_parser(). The SMTP server returned "250 ...". */ 00174 00175 #define SMTP_CLIENT_IDENTIFICATION_OK 250 00176 00177 /*! \brief Return value for the function response_parser(). The SMTP server returned "250 ...". */ 00178 00179 #define SMTP_FROM_OK 250 00180 00181 /*! \brief Return value for the function response_parser(). The SMTP server returned "250 ...". */ 00182 00183 #define SMTP_RCPT_OK 250 00184 00185 /*! \brief Return value for the function response_parser(). The SMTP server returned "354 ...". */ 00186 00187 #define SMTP_DATA_OK 354 00188 00189 /*! \brief Return value for the function response_parser(). The SMTP server returned "250 ...". */ 00190 00191 #define SMTP_END_OF_DATA_OK 250 00192 00193 /*! \brief Return value for the function response_parser(). The SMTP server an invalid response. */ 00194 00195 #define SMTP_INVALID_ANSWER -1 00196 00197 /* ------------------------------------------------- */ 00198 /* Constants used to format output to the SMTP */ 00199 /* server. */ 00200 /* ------------------------------------------------- */ 00201 00202 #define SMTP_FROM_TAG_START "MAIL FROM:<" 00203 #define SMTP_FROM_TAG_STOP ">\r\n" 00204 00205 #define SMTP_RCPT_TAG_START "RCPT TO:<" 00206 #define SMTP_RCPT_TAG_STOP ">\r\n" 00207 00208 #define MY_SMTP_HEADER 00209 #endif 00210 00211 #ifdef __cplusplus 00212 } 00213 #endif 00214