Data Structures | |
| struct | _MAILENVELOPE |
| Mail envelope structure type. More... | |
| struct | _SMTPCLIENTSESSION |
| SMTP session structure type. More... | |
Defines | |
| #define | MAX_MAIL_RCPTS 4 |
| Maximum number of recipients. | |
| #define | SMTP_BUFSIZ 256 |
| Size of the SMTP buffer. | |
| #define | SMTP_TIMEOUT 600000 |
Typedefs | |
| typedef struct _MAILENVELOPE | MAILENVELOPE |
| Mail envelope structure type. | |
| typedef struct _SMTPCLIENTSESSION | SMTPCLIENTSESSION |
| SMTP session structure type. | |
Functions | |
| const char * | NutSmtpReceiveResponse (SMTPCLIENTSESSION *si) |
| Read a response line from the server. | |
| const char * | NutSmtpSendCommand (SMTPCLIENTSESSION *si, const char *fmt,...) |
| Send command to the server and return the first response line. | |
| void | NutSmtpDisconnect (SMTPCLIENTSESSION *si) |
| Terminate an SMTP session. | |
| SMTPCLIENTSESSION * | NutSmtpConnect (uint32_t ip, uint16_t port) |
| Start an SMTP session. | |
| int | NutSmtpLogin (SMTPCLIENTSESSION *si, char *host, char *user, char *pass) |
| Identify the client SMTP to the server. | |
| int | NutSmtpSendMailRequest (SMTPCLIENTSESSION *si, MAILENVELOPE *me) |
| Send mail request. | |
| int | NutSmtpSendMailHeader (SMTPCLIENTSESSION *si, MAILENVELOPE *me) |
| Send major mail header lines. | |
| int | NutSmtpSendEncodedLines (SMTPCLIENTSESSION *si, const char *text) |
| Send encoded email text lines. | |
| const char * | NutSmtpSendMail (SMTPCLIENTSESSION *si, MAILENVELOPE *me) |
| Send an email via an active SMTP session. | |
Recipient Status Bits | |
| #define | MAIL_RCPT_TYPE 0x03 |
| Recipient type mask. | |
| #define | MAIL_RCPT_TO 0x01 |
| Standard recipient type. | |
| #define | MAIL_RCPT_CC 0x02 |
| Carbon copy recipient type. | |
| #define | MAIL_RCPT_BCC 0x03 |
| Blind carbon copy recipient type. | |
| #define | MAIL_RCPT_ACPT 0x20 |
| Recipient accepted flag. | |
| #define | MAIL_RCPT_SENT 0x40 |
| Recipient processed flag. | |
| #define | MAIL_RCPT_FAIL 0x80 |
| Recipient failed flag. | |
| #define | MAIL_RCPT_DONE (MAIL_RCPT_SENT | MAIL_RCPT_FAIL) |
| Recipient done mask. | |
Server Features | |
| #define | SMTPFEAT_VINTAGE 0x00000001 |
| Server doesn't support ESMTP. | |
| #define | SMTPFEAT_AUTH_LOGIN 0x00000002 |
| Server supports LOGIN authentication. | |
| #define | SMTPFEAT_AUTH_PLAIN 0x00000004 |
| Server supports PLAIN authentication. | |
| #define MAX_MAIL_RCPTS 4 |
Maximum number of recipients.
Referenced by NutSmtpSendMail(), and NutSmtpSendMailRequest().
| #define MAIL_RCPT_TYPE 0x03 |
Recipient type mask.
| #define MAIL_RCPT_TO 0x01 |
Standard recipient type.
Referenced by NutSmtpSendMailHeader().
| #define MAIL_RCPT_CC 0x02 |
Carbon copy recipient type.
Referenced by NutSmtpSendMailHeader().
| #define MAIL_RCPT_BCC 0x03 |
Blind carbon copy recipient type.
| #define MAIL_RCPT_ACPT 0x20 |
Recipient accepted flag.
Referenced by NutSmtpSendMail(), and NutSmtpSendMailRequest().
| #define MAIL_RCPT_SENT 0x40 |
Recipient processed flag.
Referenced by NutSmtpSendMail().
| #define MAIL_RCPT_FAIL 0x80 |
Recipient failed flag.
Referenced by NutSmtpSendMailRequest().
| #define MAIL_RCPT_DONE (MAIL_RCPT_SENT | MAIL_RCPT_FAIL) |
Recipient done mask.
Referenced by NutSmtpSendMailRequest().
| #define SMTP_BUFSIZ 256 |
Size of the SMTP buffer.
Referenced by NutSmtpSendEncodedLines().
| #define SMTPFEAT_VINTAGE 0x00000001 |
Server doesn't support ESMTP.
Referenced by NutSmtpLogin().
| #define SMTPFEAT_AUTH_LOGIN 0x00000002 |
Server supports LOGIN authentication.
Referenced by NutSmtpLogin().
| #define SMTPFEAT_AUTH_PLAIN 0x00000004 |
Server supports PLAIN authentication.
Referenced by NutSmtpLogin().
| #define SMTP_TIMEOUT 600000 |
Referenced by NutSmtpConnect().
| typedef struct _MAILENVELOPE MAILENVELOPE |
Mail envelope structure type.
| typedef struct _SMTPCLIENTSESSION SMTPCLIENTSESSION |
SMTP session structure type.
| const char* NutSmtpReceiveResponse | ( | SMTPCLIENTSESSION * | si | ) |
Read a response line from the server.
References fgets(), NULL, NUTASSERT, _SMTPCLIENTSESSION::smtp_buff, _SMTPCLIENTSESSION::smtp_stream, and strchr().
Referenced by NutSmtpConnect(), NutSmtpLogin(), NutSmtpSendCommand(), and NutSmtpSendMail().
| const char* NutSmtpSendCommand | ( | SMTPCLIENTSESSION * | si, |
| const char * | fmt, | ||
| ... | |||
| ) |
Send command to the server and return the first response line.
If a multi-line response is expected, the caller may use NutSmtpReceiveResponse() to receive additional response lines.
| fmt | Format string containing conversion specifications like printf. |
References fflush(), fputs(), NULL, NUTASSERT, NutSmtpReceiveResponse(), _SMTPCLIENTSESSION::smtp_stream, and vfprintf().
Referenced by NutSmtpDisconnect(), NutSmtpLogin(), NutSmtpSendMail(), and NutSmtpSendMailRequest().
| void NutSmtpDisconnect | ( | SMTPCLIENTSESSION * | si | ) |
Terminate an SMTP session.
Gracefully closes the SMTP connection.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
References fclose(), free(), NULL, NUTASSERT, NutSmtpSendCommand(), NutTcpCloseSocket(), _SMTPCLIENTSESSION::smtp_sock, and _SMTPCLIENTSESSION::smtp_stream.
Referenced by NutSmtpConnect().
| SMTPCLIENTSESSION* NutSmtpConnect | ( | uint32_t | ip, |
| uint16_t | port | ||
| ) |
Start an SMTP session.
| ip | IP address of the host to connect. |
| port | Port number to connect. Typically port 25 is used by SMTP. |
References _fdopen(), calloc, NULL, NutSmtpDisconnect(), NutSmtpReceiveResponse(), NutTcpConnect(), NutTcpCreateSocket(), NutTcpSetSockOpt(), _SMTPCLIENTSESSION::smtp_sock, _SMTPCLIENTSESSION::smtp_stream, SMTP_TIMEOUT, and SO_RCVTIMEO.
| int NutSmtpLogin | ( | SMTPCLIENTSESSION * | si, |
| char * | host, | ||
| char * | user, | ||
| char * | pass | ||
| ) |
Identify the client SMTP to the server.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
| host | Primary host name, or NULL if the local host has no name. |
| user | Login name. Set to NULL if authorization is not required. |
| pass | Login password. Ignored if login name is set to NULL. |
References malloc(), memcpy(), NULL, NUTASSERT, NutSmtpReceiveResponse(), NutSmtpSendCommand(), _SMTPCLIENTSESSION::smtp_buff, _SMTPCLIENTSESSION::smtp_feat, SMTPFEAT_AUTH_LOGIN, SMTPFEAT_AUTH_PLAIN, SMTPFEAT_VINTAGE, strlen(), strncmp(), and strstr().
| int NutSmtpSendMailRequest | ( | SMTPCLIENTSESSION * | si, |
| MAILENVELOPE * | me | ||
| ) |
Send mail request.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
| me | Pointer to the MAILENVELOPE structure. |
References _MAILENVELOPE::mail_from, _MAILENVELOPE::mail_rcpt, MAIL_RCPT_ACPT, MAIL_RCPT_DONE, MAIL_RCPT_FAIL, _MAILENVELOPE::mail_rcpt_stat, MAX_MAIL_RCPTS, NULL, NUTASSERT, NutSmtpSendCommand(), and rc.
Referenced by NutSmtpSendMail().
| int NutSmtpSendMailHeader | ( | SMTPCLIENTSESSION * | si, |
| MAILENVELOPE * | me | ||
| ) |
Send major mail header lines.
This function will send the following header lines:
The header information must be supplied by the caller in the mail envelope structure.
Note, that BCC recipients are not included.
The caller may add additional headers using stdio functions with the stream handle available in the SMTPCLIENTSESSION structure.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
| me | Pointer to the MAILENVELOPE structure. |
References fprintf(), gmtime(), _MAILENVELOPE::mail_date, _MAILENVELOPE::mail_from_header, MAIL_RCPT_CC, MAIL_RCPT_TO, _MAILENVELOPE::mail_subj, NULL, NUTASSERT, Rfc1123TimeString(), and _SMTPCLIENTSESSION::smtp_stream.
Referenced by NutSmtpSendMail().
| int NutSmtpSendEncodedLines | ( | SMTPCLIENTSESSION * | si, |
| const char * | text | ||
| ) |
Send encoded email text lines.
Each line will be terminated by a carriage return / linefeed pair. Lines larger than SMTP_BUFSIZ are split. This may occure in the middle of a word. A dot will be put in front of lines that start with a dot.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
| text | Pointer to a string containing the text lines to send. Lines should be separated by linefeeds and may be optionally prepended by a carriage return. If the pointer points to an empty string, nothing will be sent. |
References EOF, fputc(), fputs(), NULL, NUTASSERT, _SMTPCLIENTSESSION::smtp_buff, SMTP_BUFSIZ, and _SMTPCLIENTSESSION::smtp_stream.
Referenced by NutSmtpSendMail().
| const char* NutSmtpSendMail | ( | SMTPCLIENTSESSION * | si, |
| MAILENVELOPE * | me | ||
| ) |
Send an email via an active SMTP session.
Applications may use the following basic sequence to send an email:
#include <pro/smtpc.h> MAILENVELOPE email = { 0, "<me@ethernut.de>", "Problem", "Be warned.", { "<admin@ethernut.de>", NULL, NULL, NULL }, { MAIL_RCPT_TO, 0, 0, 0 } }; SMTPCLIENTSESSION *smtp; smtp = NutSmtpConnect(daemon_ip, 25); NutSmtpLogin(smtp, NULL, NULL, NULL); NutSmtpSendMail(smtp, &email); NutSmtpDisconnect(smtp);
More advanced mail transfers may be implemented by using the other routines of this API for sending commands or parts of an email individually. Even the stream in the session structure may be used with stdio calls.
| si | Pointer to the SMTPCLIENTSESSION structure, obtained from a previous call to NutSmtpConnect(). |
| me | Pointer to the MAILENVELOPE structure. On return, the caller should inspect the status of each recipient. |
References fflush(), fputs(), _MAILENVELOPE::mail_body, _MAILENVELOPE::mail_rcpt, MAIL_RCPT_ACPT, MAIL_RCPT_SENT, _MAILENVELOPE::mail_rcpt_stat, MAX_MAIL_RCPTS, NULL, NUTASSERT, NutSmtpReceiveResponse(), NutSmtpSendCommand(), NutSmtpSendEncodedLines(), NutSmtpSendMailHeader(), NutSmtpSendMailRequest(), and _SMTPCLIENTSESSION::smtp_stream.