Secure connection
The imap
is using plain TCP, but for the secure connection one must use imaps
.
It inherits imap
API but uses TLS. The authentication methods are: login and start tls. For the login method,
the well known port is 993:
try
{
imaps conn("imap.server.com", 993);
conn.authenticate("mailio@server.com", "mailiopass", imaps::auth_method_t::LOGIN);
message msg;
conn.fetch("inbox", 1, msg);
}
catch (imap_error& exc)
{
cout << exc.what() << endl;
}
catch (dialog_error& exc)
{
cout << exc.what() << endl;
}
For the start tls method, the well know port is 143 as for the plain IMAP connection:
try
{
imaps conn("pop3.server.com", 143);
conn.authenticate("mailio@server.com", "mailiopass", imaps::auth_method_t::START_TLS);
message msg;
conn.fetch("inbox", 1, msg);
}
catch (imap_error& exc)
{
cout << exc.what() << endl;
}
catch (dialog_error& exc)
{
cout << exc.what() << endl;
}