libwebsockets
Lightweight C library for HTML5 websockets
SMTP related functions

Data Structures

struct  lws_email
 

Enumerations

enum  lwsgs_smtp_states {
  LGSSMTP_IDLE, LGSSMTP_CONNECTING, LGSSMTP_CONNECTED, LGSSMTP_SENT_HELO,
  LGSSMTP_SENT_FROM, LGSSMTP_SENT_TO, LGSSMTP_SENT_DATA, LGSSMTP_SENT_BODY,
  LGSSMTP_SENT_QUIT
}
 

Functions

LWS_VISIBLE LWS_EXTERN int lws_email_init (struct lws_email *email, uv_loop_t *loop, int max_content)
 
LWS_VISIBLE LWS_EXTERN void lws_email_check (struct lws_email *email)
 
LWS_VISIBLE LWS_EXTERN void lws_email_destroy (struct lws_email *email)
 

Detailed Description

SMTP related functions

These apis let you communicate with a local SMTP server to send email from lws. It handles all the SMTP sequencing and protocol actions.

Your system should have postfix, sendmail or another MTA listening on port 25 and able to send email using the "mail" commandline app. Usually distro MTAs are configured for this by default.

It runs via its own libuv events if initialized (which requires giving it a libuv loop to attach to).

It operates using three callbacks, on_next() queries if there is a new email to send, on_get_body() asks for the body of the email, and on_sent() is called after the email is successfully sent.

To use it

When you have at least one email to send, call lws_email_check() to schedule starting to send it.

Enumeration Type Documentation

◆ lwsgs_smtp_states

#include <lib/libwebsockets.h>

enum lwsgs_smtp_states - where we are in SMTP protocol sequence

Enumerator
LGSSMTP_IDLE 

awaiting new email

LGSSMTP_CONNECTING 

opening tcp connection to MTA

LGSSMTP_CONNECTED 

tcp connection to MTA is connected

LGSSMTP_SENT_HELO 

sent the HELO

LGSSMTP_SENT_FROM 

sent FROM

LGSSMTP_SENT_TO 

sent TO

LGSSMTP_SENT_DATA 

sent DATA request

LGSSMTP_SENT_BODY 

sent the email body

LGSSMTP_SENT_QUIT 

sent the session quit

6960  {
6961  LGSSMTP_IDLE,
6966  LGSSMTP_SENT_TO,
6970 };
Definition: libwebsockets.h:6963
Definition: libwebsockets.h:6968
Definition: libwebsockets.h:6961
Definition: libwebsockets.h:6962
Definition: libwebsockets.h:6966
Definition: libwebsockets.h:6965
Definition: libwebsockets.h:6969
Definition: libwebsockets.h:6964
Definition: libwebsockets.h:6967

Function Documentation

◆ lws_email_check()

LWS_VISIBLE LWS_EXTERN void lws_email_check ( struct lws_email email)

#include <lib/libwebsockets.h>

lws_email_check() - Request check for new email

Parameters
emailstruct lws_email context to check

Schedules a check for new emails in 1s... call this when you have queued an email for send.

◆ lws_email_destroy()

LWS_VISIBLE LWS_EXTERN void lws_email_destroy ( struct lws_email email)

#include <lib/libwebsockets.h>

lws_email_destroy() - stop using the struct lws_email

Parameters
emailthe struct lws_email context

Stop sending email using email and free allocations

◆ lws_email_init()

LWS_VISIBLE LWS_EXTERN int lws_email_init ( struct lws_email email,
uv_loop_t *  loop,
int  max_content 
)

#include <lib/libwebsockets.h>

lws_email_init() - Initialize a struct lws_email

Parameters
emailstruct lws_email to init
looplibuv loop to use
max_contentmax email content size

Prepares a struct lws_email for use ending SMTP