Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
SMTP client

Provides SMTP/S client. More...

Classes

class  MailMessage
 
class  SmtpClient
 

Macros

#define SMTP_QUEUE_SIZE   5
 
#define SMTP_ERROR_LENGTH   40
 
#define SMTP_CODE_SERVICE_READY   220
 
#define SMTP_CODE_BYE   221
 
#define SMTP_CODE_AUTH_OK   235
 
#define SMTP_CODE_REQUEST_OK   250
 
#define SMTP_CODE_AUTH_CHALLENGE   334
 
#define SMTP_CODE_START_DATA   354
 
#define SMTP_OPT_PIPELINE   bit(0)
 
#define SMTP_OPT_STARTTLS   bit(1)
 
#define SMTP_OPT_AUTH_PLAIN   bit(2)
 
#define SMTP_OPT_AUTH_LOGIN   bit(3)
 
#define SMTP_OPT_AUTH_CRAM_MD5   bit(4)
 

Typedefs

typedef std::function< int(SmtpClient &client, int code, char *status)> SmtpClientCallback
 

Enumerations

enum  SmtpState {
  eSMTP_Banner = 0,
  eSMTP_Hello,
  eSMTP_StartTLS,
  eSMTP_SendAuth,
  eSMTP_SendingAuthLogin,
  eSMTP_RequestingAuthChallenge,
  eSMTP_SendAuthResponse,
  eSMTP_SendingAuth,
  eSMTP_Ready,
  eSMTP_SendMail,
  eSMTP_SendingMail,
  eSMTP_SendRcpt,
  eSMTP_SendingRcpt,
  eSMTP_SendData,
  eSMTP_SendingData,
  eSMTP_SendHeader,
  eSMTP_SendingHeaders,
  eSMTP_StartBody,
  eSMTP_SendingBody,
  eSMTP_Sent,
  eSMTP_Quitting,
  eSMTP_Disconnect
}
 

Functions

 SmtpClient::SmtpClient (bool autoDestroy=false)
 
bool SmtpClient::connect (const Url &url)
 Connects to remote URL. More...
 
bool SmtpClient::send (const String &from, const String &to, const String &subject, const String &body)
 Queues a single message before it is sent later to the SMTP server. More...
 
bool SmtpClient::send (MailMessage *message)
 Powerful method to queues a single message before it is sent later to the SMTP server. More...
 
MailMessageSmtpClient::getCurrentMessage ()
 Gets the current message. More...
 
size_t SmtpClient::countPending ()
 
void SmtpClient::quit ()
 Sends a quit command to the server and closes the TCP conneciton. More...
 
SmtpState SmtpClient::getState ()
 Returns the current state of the SmtpClient. More...
 
void SmtpClient::onMessageSent (SmtpClientCallback callback)
 Callback that will be called every time a message is sent successfully. More...
 
void SmtpClient::onServerError (SmtpClientCallback callback)
 Callback that will be called every an error occurs. More...
 
err_t SmtpClient::onReceive (pbuf *buf) override
 
void SmtpClient::onReadyToSendData (TcpConnectionEvent sourceEvent) override
 
void SmtpClient::sendMailHeaders (MailMessage *mail)
 
bool SmtpClient::sendMailBody (MailMessage *mail)
 

Detailed Description

Provides SMTP/S client.

Macro Definition Documentation

#define SMTP_CODE_SERVICE_READY   220

SMTP response codes

Function Documentation

bool SmtpClient::connect ( const Url url)

Connects to remote URL.

Parameters
URL- provides the protocol, remote server, port and user credentials allowed protocols:
  • smtp - clear text SMTP
  • smtps - SMTP over SSL connection
MailMessage* SmtpClient::getCurrentMessage ( )

Gets the current message.

Returns
MailMessage* message - the message, or NULL if none is scheduled
SmtpState SmtpClient::getState ( )
inline

Returns the current state of the SmtpClient.

void SmtpClient::onMessageSent ( SmtpClientCallback  callback)
inline

Callback that will be called every time a message is sent successfully.

Parameters
SmtpClientCallbackcallback
void SmtpClient::onServerError ( SmtpClientCallback  callback)
inline

Callback that will be called every an error occurs.

Parameters
SmtpClientCallbackcallback
void SmtpClient::quit ( )

Sends a quit command to the server and closes the TCP conneciton.

bool SmtpClient::send ( const String from,
const String to,
const String subject,
const String body 
)

Queues a single message before it is sent later to the SMTP server.

Parameters
String&from
String&to
String&subject
String&body the body in plain text format
Returns
true when the message was queued successfully, false otherwise
bool SmtpClient::send ( MailMessage message)

Powerful method to queues a single message before it is sent later to the SMTP server.

Parameters
MailMessage*message
Returns
true when the message was queued successfully, false otherwise