601 lines
19 KiB
C++
601 lines
19 KiB
C++
/**
|
|
* @file include/ActivMiddleware/Misc/SmtpHelper.h
|
|
*
|
|
* @brief Smtp helper class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_MISC_SMTP_HELPER_H)
|
|
#define ACTIV_MISC_SMTP_HELPER_H
|
|
|
|
#include "ActivMiddleware/ActivBase/ActivBase.h"
|
|
#include "ActivMiddleware/ActivBase/StatusCodeException.h"
|
|
#include "ActivMiddleware/ActivBase/Thread.h"
|
|
#include "ActivMiddleware/ActivBase/Ip/IpManager.h"
|
|
|
|
#include "ActivMiddleware/Misc/Fmt.h"
|
|
|
|
#include ACTIV_BOOST_INCLUDE(tokenizer.hpp)
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Smtp helper class.
|
|
*/
|
|
class SmtpHelper : private Boost::noncopyable
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Email class.
|
|
*/
|
|
class Email
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param fromAddress the address the message is from.
|
|
* @param toAddressList the 'to' address list.
|
|
* @param ccAddressList the 'cc' address list.
|
|
* @param bccAddressList the 'bcc'address list.
|
|
* @param subject the message subject.
|
|
* @param text the message text.
|
|
*/
|
|
Email(const String &fromAddress, const String &toAddressList, const String &ccAddressList,
|
|
const String &bccAddressList, const String &subject, const String &text);
|
|
|
|
const String m_fromAddress; ///< the address the message is from.
|
|
const String m_toAddressList; ///< the 'to' address list.
|
|
const String m_ccAddressList; ///< the 'cc' address list.
|
|
const String m_bccAddressList; ///< the 'bcc' address list.
|
|
const String m_subject; ///< the message subject.
|
|
const String m_text; ///< the message text.
|
|
};
|
|
|
|
static const uint16_t DEFAULT_PORT_NUMBER = 25; // The default port number.
|
|
static const uint32_t DEFAULT_READ_TIMEOUT = 60; // The default read timeout.
|
|
|
|
/**
|
|
* @brief Default constructor.
|
|
*
|
|
* @param readTimeout the read timeout.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
SmtpHelper(const uint32_t readTimeout = DEFAULT_READ_TIMEOUT);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param server the server.
|
|
* @param portNumber the port number.
|
|
* @param readTimeout the read timeout.
|
|
* @param hostname the hostname.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
SmtpHelper(const String &server, const uint16_t portNumber = DEFAULT_PORT_NUMBER, const uint32_t readTimeout = DEFAULT_READ_TIMEOUT, const String &hostname = GetHostname());
|
|
|
|
/**
|
|
* @brief Destructor.
|
|
*/
|
|
~SmtpHelper();
|
|
|
|
/**
|
|
* @brief Connect to the server.
|
|
*
|
|
* @param server the server.
|
|
* @param portNumber the port number.
|
|
* @param hostname the hostname.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
StatusCode Connect(const String &server, const uint16_t portNumber = DEFAULT_PORT_NUMBER, const String &hostname = GetHostname());
|
|
|
|
/**
|
|
* @brief Disconnect from the server.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
StatusCode Disconnect();
|
|
|
|
/**
|
|
* @brief Post a message.
|
|
*
|
|
* @param fromAddress the address the message is from.
|
|
* @param toAddressList the 'to' address list.
|
|
* @param ccAddressList the 'cc' address list.
|
|
* @param bccAddressList the 'bcc'address list.
|
|
* @param subject the message subject.
|
|
* @param text the message text.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
StatusCode PostMessage(const String &fromAddress, const String &toAddressList, const String &ccAddressList, const String &bccAddressList, const String &subject, const String &text);
|
|
|
|
/**
|
|
* @brief Is connected to the server.
|
|
*
|
|
* @return whether the object is connected to the server.
|
|
*/
|
|
bool IsConnected() const;
|
|
|
|
/**
|
|
* @brief Get the hostname.
|
|
*
|
|
* @return the hostname.
|
|
*/
|
|
static String GetHostname();
|
|
|
|
/**
|
|
* @brief Post an email asynchronously.
|
|
*
|
|
* Starts a new thread to send an email. An exception is thrown only on failure of starting a new thread, not if the attempt to
|
|
* send the email fails.
|
|
*
|
|
* @param email the email to send.
|
|
* @param server the mail server to use.
|
|
* @param portNumber the port number.
|
|
* @param readTimeout the read timeout.
|
|
* @param hostname the hostname.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
static void PostEmail(const Email &email, const String &server, const uint16_t portNumber = DEFAULT_PORT_NUMBER, const uint32_t readTimeout = DEFAULT_READ_TIMEOUT, const String &hostname = GetHostname());
|
|
|
|
private:
|
|
/**
|
|
* @brief Send email thread.
|
|
*
|
|
* This thread deletes itself when it finishes.
|
|
*/
|
|
class PostEmailThread : public Thread
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param email the email to send.
|
|
* @param server the mail server to use.
|
|
* @param portNumber the port number.
|
|
* @param readTimeout the read timeout.
|
|
* @param hostname the hostname.
|
|
*/
|
|
PostEmailThread(const Email &email, const String &server, const uint16_t portNumber, const uint32_t readTimeout, const String &hostname);
|
|
|
|
private:
|
|
// Thread interface
|
|
virtual StatusCode Process(void *pData) ACTIV_OVERRIDE;
|
|
|
|
const Email m_email; ///< the email to send.
|
|
const String m_server; ///< the mail server to use.
|
|
const uint16_t m_portNumber; ///< the port number.
|
|
const uint32_t m_readTimeout; ///< the read timeout.
|
|
const String m_hostname; ///< the hostname.
|
|
};
|
|
|
|
/**
|
|
* @brief Confirm reply code.
|
|
*
|
|
* @param replyCode the reply code.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_FAILURE
|
|
*/
|
|
StatusCode ConfirmReplyCode(const String &replyCode);
|
|
|
|
/**
|
|
* @brief Connect the socket.
|
|
*
|
|
* @param server the server.
|
|
* @param portNumber the port number.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_FAILURE
|
|
*/
|
|
StatusCode ConnectSocket(const String &server, const uint16_t portNumber);
|
|
|
|
/**
|
|
* @brief Disconnect the socket.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_FAILURE
|
|
*/
|
|
StatusCode DisconnectSocket();
|
|
|
|
/**
|
|
* @brief Read data from the socket.
|
|
*
|
|
* @param pData a pointer to the data buffer.
|
|
* @param size the size of the data buffer.
|
|
* @param length the number of characters read.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_FAILURE
|
|
* @retval STATUS_CODE_TIMEOUT
|
|
*/
|
|
StatusCode ReadSocket(void * const pData, const size_t size, size_t &length);
|
|
|
|
/**
|
|
* @brief Write data to the socket.
|
|
*
|
|
* @param pData a pointer to the data buffer.
|
|
* @param length the number of characters to write.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval STATUS_CODE_FAILURE
|
|
*/
|
|
StatusCode WriteSocket(const void * const pData, const size_t length);
|
|
|
|
SOCKET m_socket; ///< The socket
|
|
const uint32_t m_readTimeout; ///< The read timeout in seconds.
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline SmtpHelper::SmtpHelper(const uint32_t readTimeout) :
|
|
m_socket(INVALID_SOCKET),
|
|
m_readTimeout(readTimeout)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline SmtpHelper::SmtpHelper(const String &server, const uint16_t portNumber, const uint32_t readTimeout, const String &hostname) :
|
|
m_socket(INVALID_SOCKET),
|
|
m_readTimeout(readTimeout)
|
|
{
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, Connect(server, portNumber, hostname));
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline SmtpHelper::~SmtpHelper()
|
|
{
|
|
if (IsConnected())
|
|
(void) Disconnect();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::Connect(const String &server, const uint16_t portNumber, const String &hostname)
|
|
{
|
|
if (IsConnected())
|
|
return STATUS_CODE_ALREADY_CONNECTED;
|
|
|
|
try
|
|
{
|
|
ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, ConnectSocket(server, portNumber));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("220"));
|
|
|
|
const String heloCommand("HELO " + hostname + "\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(heloCommand.c_str(), heloCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
}
|
|
catch (StatusCodeException &statusCodeException)
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return static_cast<const StatusCode>(statusCodeException.m_errorCode);
|
|
}
|
|
ACTIV_CATCH_ALL()
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return STATUS_CODE_FAILURE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::Disconnect()
|
|
{
|
|
if (!IsConnected())
|
|
return STATUS_CODE_NOT_CONNECTED;
|
|
|
|
try
|
|
{
|
|
const String quitCommand("QUIT\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(quitCommand.c_str(), quitCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("221"));
|
|
|
|
ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, DisconnectSocket());
|
|
}
|
|
catch (StatusCodeException &statusCodeException)
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return static_cast<const StatusCode>(statusCodeException.m_errorCode);
|
|
}
|
|
ACTIV_CATCH_ALL()
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return STATUS_CODE_FAILURE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::PostMessage(const String &fromAddress, const String &toAddressList, const String &ccAddressList, const String &bccAddressList, const String &subject, const String &text)
|
|
{
|
|
if (!IsConnected())
|
|
return STATUS_CODE_NOT_CONNECTED;
|
|
|
|
try
|
|
{
|
|
const String mailFromCommand("MAIL FROM: " + fromAddress + "\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(mailFromCommand.c_str(), mailFromCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
|
|
typedef Boost::char_separator<char> CharSeparator;
|
|
typedef Boost::tokenizer<CharSeparator, String::const_iterator, String> Tokenizer;
|
|
const CharSeparator semiColonSeparator(";");
|
|
|
|
Tokenizer tokenizer(toAddressList, semiColonSeparator);
|
|
|
|
for (Tokenizer::const_iterator iterator = tokenizer.begin(), iteratorEnd = tokenizer.end(); iteratorEnd != iterator; ++iterator)
|
|
{
|
|
const String rcptToCommand("RCPT TO: " + *iterator + "\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(rcptToCommand.c_str(), rcptToCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
}
|
|
|
|
tokenizer.assign(ccAddressList, semiColonSeparator);
|
|
|
|
for (Tokenizer::const_iterator iterator = tokenizer.begin(), iteratorEnd = tokenizer.end(); iteratorEnd != iterator; ++iterator)
|
|
{
|
|
const String rcptToCommand("RCPT TO: " + *iterator + "\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(rcptToCommand.c_str(), rcptToCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
}
|
|
|
|
tokenizer.assign(bccAddressList, semiColonSeparator);
|
|
|
|
for (Tokenizer::const_iterator iterator = tokenizer.begin(), iteratorEnd = tokenizer.end(); iteratorEnd != iterator; ++iterator)
|
|
{
|
|
const String rcptToCommand("RCPT TO: " + *iterator + "\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(rcptToCommand.c_str(), rcptToCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
}
|
|
|
|
const String dataCommand("DATA\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(dataCommand.c_str(), dataCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("354"));
|
|
|
|
String dataHeader;
|
|
|
|
dataHeader += String("From: " + fromAddress + "\r\n");
|
|
dataHeader += String("To: " + toAddressList + "\r\n");
|
|
dataHeader += String("Cc: " + ccAddressList + "\r\n");
|
|
dataHeader += String("Subject: " + subject + "\r\n");
|
|
dataHeader += String("\r\n");
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(dataHeader.c_str(), dataHeader.length()));
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(text.c_str(), text.length()));
|
|
|
|
const String endOfDataCommand("\r\n.\r\n");
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, WriteSocket(endOfDataCommand.c_str(), endOfDataCommand.length()));
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, ConfirmReplyCode("250"));
|
|
}
|
|
catch (StatusCodeException &statusCodeException)
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return static_cast<const StatusCode>(statusCodeException.m_errorCode);
|
|
}
|
|
ACTIV_CATCH_ALL()
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return STATUS_CODE_FAILURE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool SmtpHelper::IsConnected() const
|
|
{
|
|
return (INVALID_SOCKET != m_socket);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline String SmtpHelper::GetHostname()
|
|
{
|
|
return IpManager::GetHostName();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::ConfirmReplyCode(const String &replyCode)
|
|
{
|
|
char buffer[1024];
|
|
size_t length;
|
|
ACTIV_RETURN_RESULT_IF_UNLIKELY(STATUS_CODE_SUCCESS, !=, ReadSocket(buffer, ACTIV_ARRAY_SIZE(buffer), length));
|
|
|
|
return (((length >= replyCode.length()) && (0 == ::memcmp(buffer, replyCode.c_str(), replyCode.length()))) ? STATUS_CODE_SUCCESS : STATUS_CODE_FAILURE);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::ConnectSocket(const String &server, const uint16_t portNumber)
|
|
{
|
|
try
|
|
{
|
|
IpAddress remoteAddress(SOCK_STREAM, IPPROTO_TCP);
|
|
IpManager::GetIpAddress(server, portNumber, remoteAddress);
|
|
|
|
m_socket = ::socket(remoteAddress.GetFamily(), remoteAddress.GetType(), remoteAddress.GetProtocol());
|
|
|
|
if (INVALID_SOCKET == m_socket)
|
|
ACTIV_THROW(Activ::StatusCodeException, STATUS_CODE_FAILURE);
|
|
|
|
if (SOCKET_ERROR == ::connect(m_socket, &remoteAddress.GetAddress().Address, remoteAddress.GetLength()))
|
|
ACTIV_THROW(Activ::StatusCodeException, STATUS_CODE_FAILURE);
|
|
}
|
|
catch (StatusCodeException &statusCodeException)
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return static_cast<const StatusCode>(statusCodeException.m_errorCode);
|
|
}
|
|
ACTIV_CATCH_ALL()
|
|
{
|
|
(void) DisconnectSocket();
|
|
|
|
return STATUS_CODE_FAILURE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::DisconnectSocket()
|
|
{
|
|
if (INVALID_SOCKET != m_socket)
|
|
(void) closesocket(m_socket);
|
|
|
|
m_socket = INVALID_SOCKET;
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::ReadSocket(void * const pData, const size_t size, size_t &length)
|
|
{
|
|
fd_set readFds;
|
|
FD_ZERO(&readFds);
|
|
FD_SET(m_socket, &readFds);
|
|
|
|
struct timeval timeout;
|
|
timeout.tv_sec = m_readTimeout;
|
|
timeout.tv_usec = 0;
|
|
|
|
int result = ::select(static_cast<int>(m_socket + 1), &readFds, 0, 0, &timeout);
|
|
|
|
if (SOCKET_ERROR == result)
|
|
return STATUS_CODE_FAILURE;
|
|
if (0 == result)
|
|
return STATUS_CODE_TIMEOUT;
|
|
|
|
result = ::recv(m_socket, reinterpret_cast<char * const>(pData), static_cast<const int>(size), 0);
|
|
|
|
if (SOCKET_ERROR == result)
|
|
return STATUS_CODE_FAILURE;
|
|
|
|
length = static_cast<const size_t>(result);
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::WriteSocket(const void * const pData, const size_t length)
|
|
{
|
|
const int toWrite = static_cast<const int>(length);
|
|
|
|
for (int written = 0, result; written < toWrite; written += result)
|
|
{
|
|
result = ::send(m_socket, reinterpret_cast<const char * const>(pData) + written, toWrite - written, 0);
|
|
|
|
if (SOCKET_ERROR == result)
|
|
return STATUS_CODE_FAILURE;
|
|
}
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void SmtpHelper::PostEmail(const Email &email, const String &server, const uint16_t portNumber, const uint32_t readTimeout, const String &hostname)
|
|
{
|
|
CxxYZ::unique_ptr<PostEmailThread> pPostEmailThread(new (std::nothrow) PostEmailThread(email, server, portNumber, readTimeout, hostname));
|
|
if (!pPostEmailThread)
|
|
ACTIV_THROW(StatusCodeException, STATUS_CODE_HEAP_EMPTY);
|
|
|
|
pPostEmailThread->Start(); // this might throw an exception
|
|
|
|
// if we get to here, thread started ok and will delete itself
|
|
pPostEmailThread.release();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline SmtpHelper::Email::Email(const String &fromAddress, const String &toAddressList, const String &ccAddressList,
|
|
const String &bccAddressList, const String &subject, const String &text) :
|
|
m_fromAddress(fromAddress),
|
|
m_toAddressList(toAddressList),
|
|
m_ccAddressList(ccAddressList),
|
|
m_bccAddressList(bccAddressList),
|
|
m_subject(subject),
|
|
m_text(text)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline SmtpHelper::PostEmailThread::PostEmailThread(const Email &email, const String &server, const uint16_t portNumber, const uint32_t readTimeout, const String &hostname) :
|
|
m_email(email),
|
|
m_server(server),
|
|
m_portNumber(portNumber),
|
|
m_readTimeout(readTimeout),
|
|
m_hostname(hostname)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode SmtpHelper::PostEmailThread::Process(void *pData)
|
|
{
|
|
SmtpHelper smtpHelper(m_readTimeout);
|
|
|
|
StatusCode statusCode = smtpHelper.Connect(m_server, m_portNumber, m_hostname);
|
|
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, Fmt::Format("Error connecting to email server, subject '{}', error {} - {}", m_email.m_subject, static_cast<const uint32_t>(statusCode), StatusCodeToString(statusCode)));
|
|
return statusCode;
|
|
}
|
|
|
|
statusCode = smtpHelper.PostMessage(m_email.m_fromAddress, m_email.m_toAddressList, m_email.m_ccAddressList,
|
|
m_email.m_bccAddressList, m_email.m_subject, m_email.m_text);
|
|
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, Fmt::Format("Error posting email message, subject '{}', error {} - {}", m_email.m_subject, static_cast<const uint32_t>(statusCode), StatusCodeToString(statusCode)));
|
|
return statusCode;
|
|
}
|
|
|
|
delete this;
|
|
|
|
return STATUS_CODE_SUCCESS;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_MISC_SMTP_HELPER_H)
|