smtp_client.c File Reference

SMTP client (Simple Mail Transfer Protocol) More...

#include "core/net.h"
#include "smtp/smtp_client.h"
#include "smtp/smtp_client_auth.h"
#include "smtp/smtp_client_transport.h"
#include "smtp/smtp_client_misc.h"
#include "str.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SMTP_TRACE_LEVEL
 

Functions

error_t smtpClientInit (SmtpClientContext *context)
 Initialize SMTP client context. More...
 
error_t smtpClientRegisterTlsInitCallback (SmtpClientContext *context, SmtpClientTlsInitCallback callback)
 Register TLS initialization callback function. More...
 
error_t smtpClientSetTimeout (SmtpClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t smtpClientBindToInterface (SmtpClientContext *context, NetInterface *interface)
 Bind the SMTP client to a particular network interface. More...
 
error_t smtpClientConnect (SmtpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort, SmtpConnectionMode mode)
 Establish a connection with the specified SMTP server. More...
 
error_t smtpClientLogin (SmtpClientContext *context, const char_t *username, const char_t *password)
 Login to the SMTP server using the provided user name and password. More...
 
error_t smtpClientSetContentType (SmtpClientContext *context, const char_t *contentType)
 Set the content type to be used. More...
 
error_t smtpClientSetMultipartBoundary (SmtpClientContext *context, const char_t *boundary)
 Define the boundary string to be used (multipart encoding) More...
 
error_t smtpClientWriteMailHeader (SmtpClientContext *context, const SmtpMailAddr *from, const SmtpMailAddr *recipients, uint_t numRecipients, const char_t *subject)
 Write email header. More...
 
error_t smtpClientWriteMailBody (SmtpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write email body. More...
 
error_t smtpClientWriteMultipartHeader (SmtpClientContext *context, const char_t *filename, const char_t *contentType, const char_t *contentTransferEncoding, bool_t last)
 Write multipart header. More...
 
error_t smtpClientWriteMultipartBody (SmtpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write data to the the multipart body. More...
 
error_t smtpClientCloseMailBody (SmtpClientContext *context)
 Complete email sending process and wait for server's status. More...
 
uint_t smtpClientGetReplyCode (SmtpClientContext *context)
 Retrieve server's reply code. More...
 
error_t smtpClientDisconnect (SmtpClientContext *context)
 Gracefully disconnect from the SMTP server. More...
 
error_t smtpClientClose (SmtpClientContext *context)
 Close the connection with the SMTP server. More...
 
void smtpClientDeinit (SmtpClientContext *context)
 Release SMTP client context. More...
 

Detailed Description

SMTP client (Simple Mail Transfer Protocol)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

SMTP is designed as a mail transport and delivery protocol. Refer to the following RFCs for complete details:

  • RFC 5321: Simple Mail Transfer Protocol
  • RFC 4954: SMTP Service Extension for Authentication
  • RFC 3207: SMTP Service Extension for Secure SMTP over TLS
Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.6

Definition in file smtp_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SMTP_TRACE_LEVEL

Definition at line 40 of file smtp_client.c.

Function Documentation

◆ smtpClientBindToInterface()

error_t smtpClientBindToInterface ( SmtpClientContext context,
NetInterface interface 
)

Bind the SMTP client to a particular network interface.

Parameters
[in]contextPointer to the SMTP client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 147 of file smtp_client.c.

◆ smtpClientClose()

error_t smtpClientClose ( SmtpClientContext context)

Close the connection with the SMTP server.

Parameters
[in]contextPointer to the SMTP client context
Returns
Error code

Definition at line 1278 of file smtp_client.c.

◆ smtpClientCloseMailBody()

error_t smtpClientCloseMailBody ( SmtpClientContext context)

Complete email sending process and wait for server's status.

Parameters
[in]contextPointer to the SMTP client context
Returns
Error code

Definition at line 1081 of file smtp_client.c.

◆ smtpClientConnect()

error_t smtpClientConnect ( SmtpClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort,
SmtpConnectionMode  mode 
)

Establish a connection with the specified SMTP server.

Parameters
[in]contextPointer to the SMTP client context
[in]serverIpAddrIP address of the SMTP server
[in]serverPortPort number
[in]modeSMTP connection mode
Returns
Error code

Definition at line 171 of file smtp_client.c.

◆ smtpClientDeinit()

void smtpClientDeinit ( SmtpClientContext context)

Release SMTP client context.

Parameters
[in]contextPointer to the SMTP client context

Definition at line 1299 of file smtp_client.c.

◆ smtpClientDisconnect()

error_t smtpClientDisconnect ( SmtpClientContext context)

Gracefully disconnect from the SMTP server.

Parameters
[in]contextPointer to the SMTP client context
Returns
Error code

Definition at line 1186 of file smtp_client.c.

◆ smtpClientGetReplyCode()

uint_t smtpClientGetReplyCode ( SmtpClientContext context)

Retrieve server's reply code.

Parameters
[in]contextPointer to the SMTP client context
Returns
SMTP reply code

Definition at line 1159 of file smtp_client.c.

◆ smtpClientInit()

error_t smtpClientInit ( SmtpClientContext context)

Initialize SMTP client context.

Parameters
[in]contextPointer to the SMTP client context
Returns
Error code

Definition at line 61 of file smtp_client.c.

◆ smtpClientLogin()

error_t smtpClientLogin ( SmtpClientContext context,
const char_t username,
const char_t password 
)

Login to the SMTP server using the provided user name and password.

Parameters
[in]contextPointer to the SMTP client context
[in]usernameNULL-terminated string containing the user name
[in]passwordNULL-terminated string containing the user's password
Returns
Error code

Definition at line 431 of file smtp_client.c.

◆ smtpClientRegisterTlsInitCallback()

error_t smtpClientRegisterTlsInitCallback ( SmtpClientContext context,
SmtpClientTlsInitCallback  callback 
)

Register TLS initialization callback function.

Parameters
[in]contextPointer to the SMTP client context
[in]callbackTLS initialization callback function
Returns
Error code

Definition at line 102 of file smtp_client.c.

◆ smtpClientSetContentType()

error_t smtpClientSetContentType ( SmtpClientContext context,
const char_t contentType 
)

Set the content type to be used.

Parameters
[in]contextPointer to the SMTP client context
[in]contentTypeNULL-terminated string that holds the content type
Returns
Error code

Definition at line 484 of file smtp_client.c.

◆ smtpClientSetMultipartBoundary()

error_t smtpClientSetMultipartBoundary ( SmtpClientContext context,
const char_t boundary 
)

Define the boundary string to be used (multipart encoding)

Parameters
[in]contextPointer to the SMTP client context
[in]boundaryNULL-terminated string that holds the boundary string
Returns
Error code

Definition at line 520 of file smtp_client.c.

◆ smtpClientSetTimeout()

error_t smtpClientSetTimeout ( SmtpClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the SMTP client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 126 of file smtp_client.c.

◆ smtpClientWriteMailBody()

error_t smtpClientWriteMailBody ( SmtpClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write email body.

Parameters
[in]contextPointer to the SMTP client context
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
[in]writtenNumber of bytes that have been written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 727 of file smtp_client.c.

◆ smtpClientWriteMailHeader()

error_t smtpClientWriteMailHeader ( SmtpClientContext context,
const SmtpMailAddr from,
const SmtpMailAddr recipients,
uint_t  numRecipients,
const char_t subject 
)

Write email header.

Parameters
[in]contextPointer to the SMTP client context
[in]fromEmail address of the sender
[in]recipientsEmail addresses of the recipients
[in]numRecipientsNumber of email addresses in the list
[in]subjectNULL-terminsated string containing the email subject
Returns
Error code

Definition at line 559 of file smtp_client.c.

◆ smtpClientWriteMultipartBody()

error_t smtpClientWriteMultipartBody ( SmtpClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write data to the the multipart body.

Parameters
[in]contextPointer to the SMTP client context
[in]dataPointer to the buffer containing the data to be transmitted
[in]lengthNumber of data bytes to send
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 934 of file smtp_client.c.

◆ smtpClientWriteMultipartHeader()

error_t smtpClientWriteMultipartHeader ( SmtpClientContext context,
const char_t filename,
const char_t contentType,
const char_t contentTransferEncoding,
bool_t  last 
)

Write multipart header.

Parameters
[in]contextPointer to the SMTP client context
[in]filenameNULL-terminated string that holds the file name (optional parameter)
[in]contentTypeNULL-terminated string that holds the content type (optional parameter)
[in]contentTransferEncodingNULL-terminated string that holds the content transfer encoding (optional parameter)
[in]lastThis flag indicates whether the multipart header is the final one
Returns
Error code

Definition at line 797 of file smtp_client.c.