Secure connection
The smtp
class is used for the plain TCP connections, meaning that all the traffic can be
monitored. In order to encrypt connections, one must use the smtps
. It inherits all features
from the smtp
but uses the TLS on top of TCP.
There are three authentication methods: none, login and start tls. The first and second work in the same manner as for the
smtp
, but the connection itself cannot be monitored. The usual port used in this case is 465.
The start tls method begins with an non-encrypted connection, before sending credentials the connection is upgraded to the TLS
(by executing the STARTTLS
command):
try
{
smtps conn("smtp.server.com", 587);
conn.authenticate("mailio@server.com", "mailiopass", smtps::auth_method_t::START_TLS);
message msg;
msg.from(mail_address("mailio library", "mailio@server.com"));
msg.add_recipient(mail_address("mailio library", "mailio@server.com"));
msg.subject("Salut, tout le monde!");
msg.content("Hello, World!");
conn.submit(msg);
}
catch (smtp_error& exc)
{
cout << exc.what() << endl;
}
catch (dialog_error& exc)
{
cout << exc.what() << endl;
}