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 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-2024 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
- Version
- 2.4.4
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] context Pointer to the SMTP client context [in] interface Network 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] context Pointer 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] context Pointer 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] context Pointer to the SMTP client context [in] serverIpAddr IP address of the SMTP server [in] serverPort Port number [in] mode SMTP 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] context Pointer 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] context Pointer 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] context Pointer 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] context Pointer 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] context Pointer to the SMTP client context [in] username NULL-terminated string containing the user name [in] password NULL-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] context Pointer to the SMTP client context [in] callback TLS 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] context Pointer to the SMTP client context [in] contentType NULL-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] context Pointer to the SMTP client context [in] boundary NULL-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] context Pointer to the SMTP client context [in] timeout Timeout 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] context Pointer to the SMTP client context [in] data Pointer to a buffer containing the data to be written [in] length Number of data bytes to write [in] written Number of bytes that have been written (optional parameter) [in] flags Set 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] context Pointer to the SMTP client context [in] from Email address of the sender [in] recipients Email addresses of the recipients [in] numRecipients Number of email addresses in the list [in] subject NULL-terminated 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 multipart body.
- Parameters
-
[in] context Pointer to the SMTP client context [in] data Pointer to the buffer containing the data to be transmitted [in] length Number of data bytes to send [out] written Actual number of bytes written (optional parameter) [in] flags Set 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] context Pointer to the SMTP client context [in] filename NULL-terminated string that holds the file name (optional parameter) [in] contentType NULL-terminated string that holds the content type (optional parameter) [in] contentTransferEncoding NULL-terminated string that holds the content transfer encoding (optional parameter) [in] last This flag indicates whether the multipart header is the final one
- Returns
- Error code
Definition at line 797 of file smtp_client.c.