Network Component
Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
|
Functions to connect to an SMTP server. More...
Functions | |
netStatus | netSMTPc_Connect (const NET_ADDR *addr) |
Start SMTP client to send an email in legacy mode. [thread-safe]. More... | |
netStatus | netSMTPc_SendMail (const NET_SMTP_MAIL *mail, const NET_SMTP_MTA *mta) |
Send an email in blocking mode. [thread-safe]. More... | |
Functions to connect to an SMTP server.
The SMTP Client supports two modes of operation. Mode of operation is selected with the function, which is used to send an email. The following are available:
The blocking mode starts with a call to netSMTPc_SendMail function. In this mode user callbacks are not used. The calling function is blocked until the operation completes and then returns the state of the operation. The blocking mode supports additional features, which are not available in legacy mode:
When the netSMTPc_SendMail function is called, the SMTP client resolves the IP address from the specified server name and opens a SMTP connection to the server. After handshaking, the SMTP Client transmits the message content. If the email attachments are specified, the client composes a multipart MIME message with the attachments. If you want to send an email with the attachment, you have to enable SMTP Client (full variant) in µVision configuration and specify file name(s) to attach.
The legacy mode starts with a connect request using netSMTPc_Connect. The SMTP client then opens a SMTP connection to the specified server. The user application then needs to wait for the callback function netSMTPc_Notify to return the state of the operation. Based on the callback event, further processing can be started.
Start SMTP client to send an email in legacy mode. [thread-safe].
[in] | addr | structure containing IP address and port of SMTP server. |
The function netSMTPc_Connect starts the SMTP client. The SMTP client then connects to an SMTP server specified with the argument addr which points to a buffer containing the IP address and port of the SMTP server. If the specified port is 0, the client uses a standard SMTP server port 25 to connect to the server.
Possible netStatus return values:
Code Example
netStatus netSMTPc_SendMail | ( | const NET_SMTP_MAIL * | mail, |
const NET_SMTP_MTA * | mta | ||
) |
Send an email in blocking mode. [thread-safe].
[in] | pointer to email content descriptor. | |
[in] | mta | pointer to mail transfer agent descriptor. |
The function netSMTPc_SendMail sends an email in blocking mode. The function blocks the calling thread and returns, when an email is sent. The function resolves server IP address from the host name, connects to the server and sends an email.
The argument mail points to a structure that contains a description of an email to send. All entries in a structure are pointers to null-terminated strings. When more parameters are specified (for example several To addresses), use a semicolon ';' character as a parameter separator.
The argument mta points to a structure with mail transfer agent parameters. This structure contains SMTP server address, port number, flags and user credentials for authentication. Server address can be either a fully qualified domain name or an IP address presented in string format.
Possible netStatus return values:
Code Example (multiple recipients and friendly names)
Code Example (utf-8 encoding for 'µ' character)