Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

SMTP client

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:
fromsource email address (must be NULL-terminated)
totarget email address (must be NULL-terminated)
subjectemail subject (must be NULL-terminated)
bodyemail body (must be NULL-terminated)
callback_fncallback function
callback_arguser 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:
usernamelogin name as passed to the server
passpassword 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:
serverIP 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:
portTCP 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_configTLS configuration

Definition at line 388 of file lwip_smtp.c.