lwIP 2.1.1 Lightweight IP stack

Modules | Functions
SMTP client
Applications

## Modules
| Options

## Functions
err_t | smtp_set_server_addr (const char *server)
void | smtp_set_server_port (u16_t port)
void | smtp_set_tls_config (struct altcp_tls_config *tls_config)
err_t | smtp_set_auth (const char *username, const char *pass)
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)
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)
void | smtp_send_mail_int (void *arg)

## Detailed Description

This is simple SMTP client for raw API. It is a minimal implementation of SMTP as specified in RFC 5321.

Example usage:

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:

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

## ◆ smtp_send_mail()

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.

## ◆ smtp_send_mail_int()

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)

## ◆ smtp_send_mail_static()

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)

## ◆ smtp_set_auth()

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

## ◆ smtp_set_server_addr()

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

## ◆ smtp_set_server_port()

void smtp_set_server_port | ( | u16_t | port | ) |

Set TCP port for next SMTP connection

Parameters

  port | TCP port

## ◆ smtp_set_tls_config()

void smtp_set_tls_config | ( | struct altcp_tls_config * | tls_config | ) |

Set TLS configuration for next SMTP connection

Parameters

  tls_config | TLS configuration