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.
Definition at line 60 of file smtpc.h.
Referenced by NutSmtpSendMail(), and NutSmtpSendMailRequest().
#define MAIL_RCPT_TO 0x01 |
Standard recipient type.
Definition at line 68 of file smtpc.h.
Referenced by NutSmtpSendMailHeader().
#define MAIL_RCPT_CC 0x02 |
Carbon copy recipient type.
Definition at line 70 of file smtpc.h.
Referenced by NutSmtpSendMailHeader().
#define MAIL_RCPT_ACPT 0x20 |
Recipient accepted flag.
Definition at line 74 of file smtpc.h.
Referenced by NutSmtpSendMail(), and NutSmtpSendMailRequest().
#define MAIL_RCPT_SENT 0x40 |
#define MAIL_RCPT_FAIL 0x80 |
Recipient failed flag.
Definition at line 78 of file smtpc.h.
Referenced by NutSmtpSendMailRequest().
#define MAIL_RCPT_DONE (MAIL_RCPT_SENT | MAIL_RCPT_FAIL) |
#define SMTP_BUFSIZ 256 |
Size of the SMTP buffer.
Definition at line 107 of file smtpc.h.
Referenced by NutSmtpSendEncodedLines().
#define SMTPFEAT_VINTAGE 0x00000001 |
#define SMTPFEAT_AUTH_LOGIN 0x00000002 |
Server supports LOGIN authentication.
Definition at line 115 of file smtpc.h.
Referenced by NutSmtpLogin().
#define SMTPFEAT_AUTH_PLAIN 0x00000004 |
Server supports PLAIN authentication.
Definition at line 117 of file smtpc.h.
Referenced by NutSmtpLogin().
#define SMTP_TIMEOUT 600000 |
Definition at line 62 of file smtpc.c.
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.
Definition at line 129 of file smtpc.c.
References fgets(), 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. |
Definition at line 159 of file smtpc.c.
References fflush(), fputs(), 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(). |
Definition at line 184 of file smtpc.c.
References fclose(), free(), 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. |
Definition at line 209 of file smtpc.c.
References _fdopen(), calloc, 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. |
Definition at line 258 of file smtpc.c.
References CONST, malloc(), memcpy(), 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. |
Definition at line 328 of file smtpc.c.
References CONST, _MAILENVELOPE::mail_from, _MAILENVELOPE::mail_rcpt, MAIL_RCPT_ACPT, MAIL_RCPT_DONE, MAIL_RCPT_FAIL, _MAILENVELOPE::mail_rcpt_stat, MAX_MAIL_RCPTS, NUTASSERT, and NutSmtpSendCommand().
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. |
Definition at line 423 of file smtpc.c.
References fprintf(), gmtime(), _MAILENVELOPE::mail_date, _MAILENVELOPE::mail_from_header, MAIL_RCPT_CC, MAIL_RCPT_TO, _MAILENVELOPE::mail_subj, 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. |
Definition at line 459 of file smtpc.c.
References EOF, fputc(), fputs(), 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. |
Definition at line 540 of file smtpc.c.
References CONST, fflush(), fputs(), _MAILENVELOPE::mail_body, _MAILENVELOPE::mail_rcpt, MAIL_RCPT_ACPT, MAIL_RCPT_SENT, _MAILENVELOPE::mail_rcpt_stat, MAX_MAIL_RCPTS, NUTASSERT, NutSmtpReceiveResponse(), NutSmtpSendCommand(), NutSmtpSendEncodedLines(), NutSmtpSendMailHeader(), NutSmtpSendMailRequest(), and _SMTPCLIENTSESSION::smtp_stream.