Network Component  Version 6.6
MDK-Professional Middleware for IP Networking
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SMTP Client

Simple Mail Transfer Protocol (SMTP) is a widely used protocol for the delivery of e-mails between TCP/IP systems and users. All steps in the e-mail system use SMTP with the exception of the final retrieval step by an e-mail recipient.

An Embedded SMTP Client can send e-mails to various recipients. A typical use is to send automated e-mail notifications to different e-mail addresses.

E-mail content can be a static predefined e-mail message or a real dynamic message. An example of a real dynamic email is one that contains the measurement results from a log file or an email with current measurement values.

SMTP Client interface functions are in the user interface module SMTP_Client_UIF.c. To add the module to your project, simply right-click on the Source group, select Add Net Item to Group, then click on User Code Template and scroll in the template files list until you find the SMTP Client template. Customize this module by changing the sender's address, the recipient's address, the subject, and the body of the email message.

The following functions are available:

The following function is included in the Network Component library rl_net.h:

Code Example SMTP_Client_UIF.c

#include <stdio.h>
#include "rl_net.h"
// Request parameters for SMTP client session.
uint32_t smtp_client_request (smtpClientRequest request, char *buf, uint32_t buflen, uint32_t *pvar) {
uint32_t len = 0;
switch (request) {
// Username to login to SMTP server
/* Example
len = sprintf (buf, "guest");
*/
break;
// Password to login to SMTP server
/* Example
len = sprintf (buf, "guest");
*/
break;
// Email address of the sender
/* Example
len = sprintf (buf, "me@domain.com");
*/
break;
// Email address of the recipient
/* Example
len = sprintf (buf, "you@domain.com");
*/
break;
// Subject of email
/* Example
len = sprintf (buf, "Hello");
*/
break;
// Email body in plain ascii format
/* Example
len = sprintf (buf, "Hello, how are you?\r\n");
*/
break;
}
return (len);
}
// Notify the user application when SMTP client operation ends.
switch (event) {
// Email successfully sent
break;
// Timeout sending email
break;
// Error when sending email
break;
}
}
// Accept or deny authentication requested by SMTP server.
bool smtp_client_accept_authentication (const uint8_t *ip_addr) {
/* Example
if (ip_addr[0] == 192 &&
ip_addr[1] == 168 &&
ip_addr[2] == 0 &&
ip_addr[3] == 1) {
// Deny authentication from local smtp server
return (false);
}
*/
return (true);
}

SMTP Client Configuration

The SMTP client configuration file Net_Config_SMTP_Client.h contains only the setting Response Timeout in seconds which is an inactivity timeout. When the SMTP Client does not receive a response from SMTP Server within this timeout, it aborts the operation.