Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
SMTP client
[Applications]
This is simple SMTP client for raw API. More...
Modules | |
| Options | |
Functions | |
| err_t | smtp_set_server_addr (const char *server) |
| Set IP address or DNS name for next SMTP connection. | |
| void | smtp_set_server_port (u16_t port) |
| Set TCP port for next SMTP connection. | |
| void | smtp_set_tls_config (struct altcp_tls_config *tls_config) |
| Set TLS configuration for next SMTP connection. | |
| err_t | smtp_set_auth (const char *username, const char *pass) |
| Set authentication parameters for next SMTP connection. | |
| err_t | smtp_send_mail (const char *from, const char *to, const char *subject, const char *body, smtp_result_fn callback_fn, void *callback_arg) |
| Send an email via the currently selected server, username and password. | |
| err_t | smtp_send_mail_static (const char *from, const char *to, const char *subject, const char *body, smtp_result_fn callback_fn, void *callback_arg) |
| Same as smtp_send_mail, but doesn't copy from, to, subject and body into an internal buffer to save memory. | |
| void | smtp_send_mail_int (void *arg) |
| Same as smtp_send_mail but takes a struct smtp_send_request as single parameter which contains all the other parameters. | |
Detailed Description
This is simple SMTP client for raw API.
It is a minimal implementation of SMTP as specified in RFC 5321.
Example usage:
{.c}
void my_smtp_result_fn(void *arg, u8_t smtp_result, u16_t srv_err, err_t err)
{
printf("mail (%p) sent with results: 0x%02x, 0x%04x, 0x%08x\n", arg,
smtp_result, srv_err, err);
}
static void my_smtp_test(void)
{
smtp_set_server_addr("mymailserver.org");
-> set both username and password as NULL if no auth needed
smtp_set_auth("username", "password");
smtp_send_mail("sender", "recipient", "subject", "body", my_smtp_result_fn,
some_argument);
}
When using from any other thread than the tcpip_thread (for NO_SYS==0), use smtp_send_mail_int()!
SMTP_BODYDH usage:
{.c}
int my_smtp_bodydh_fn(void *arg, struct smtp_bodydh *bdh)
{
if(bdh->state >= 10) {
return BDH_DONE;
}
sprintf(bdh->buffer,"Line #%2d\r\n",bdh->state);
bdh->length = strlen(bdh->buffer);
++bdh->state;
return BDH_WORKING;
}
smtp_send_mail_bodycback("sender", "recipient", "subject",
my_smtp_bodydh_fn, my_smtp_result_fn, some_argument);
Function Documentation
| err_t smtp_send_mail | ( | const char * | from, |
| const char * | to, | ||
| const char * | subject, | ||
| const char * | body, | ||
| smtp_result_fn | callback_fn, | ||
| void * | callback_arg | ||
| ) |
Send an email via the currently selected server, username and password.
- Parameters:
-
from source email address (must be NULL-terminated) to target email address (must be NULL-terminated) subject email subject (must be NULL-terminated) body email body (must be NULL-terminated) callback_fn callback function callback_arg user argument to callback_fn
- Returns:
- - ERR_OK if structures were allocated and no error occured starting the connection (this does not mean the email has been successfully sent!)
- another err_t on error.
Definition at line 585 of file lwip_smtp.c.
| void smtp_send_mail_int | ( | void * | arg ) |
Same as smtp_send_mail but takes a struct smtp_send_request as single parameter which contains all the other parameters.
To be used with tcpip_callback to send mail from interrupt context or from another thread.
WARNING: server and authentication must stay untouched until this function has run!
Usage example:
- allocate a struct smtp_send_request (in a way that is allowed in interrupt context)
- fill the members of the struct as if calling smtp_send_mail
- specify a callback_function
- set callback_arg to the structure itself
- call this function
- wait for the callback function to be called
- in the callback function, deallocate the structure (passed as arg)
Definition at line 695 of file lwip_smtp.c.
| err_t smtp_send_mail_static | ( | const char * | from, |
| const char * | to, | ||
| const char * | subject, | ||
| const char * | body, | ||
| smtp_result_fn | callback_fn, | ||
| void * | callback_arg | ||
| ) |
Same as smtp_send_mail, but doesn't copy from, to, subject and body into an internal buffer to save memory.
WARNING: the above data must stay untouched until the callback function is called (unless the function returns != ERR_OK)
Definition at line 640 of file lwip_smtp.c.
| err_t smtp_set_auth | ( | const char * | username, |
| const char * | pass | ||
| ) |
Set authentication parameters for next SMTP connection.
- Parameters:
-
username login name as passed to the server pass password passed to the server together with username
Definition at line 402 of file lwip_smtp.c.
| err_t smtp_set_server_addr | ( | const char * | server ) |
Set IP address or DNS name for next SMTP connection.
- Parameters:
-
server IP address (in ASCII representation) or DNS name of the server
Definition at line 349 of file lwip_smtp.c.
| void smtp_set_server_port | ( | u16_t | port ) |
Set TCP port for next SMTP connection.
- Parameters:
-
port TCP port
Definition at line 375 of file lwip_smtp.c.
| void smtp_set_tls_config | ( | struct altcp_tls_config * | tls_config ) |
Set TLS configuration for next SMTP connection.
- Parameters:
-
tls_config TLS configuration
Definition at line 388 of file lwip_smtp.c.
Generated on Tue Jul 12 2022 13:55:22 by
1.7.2