Receiving a message
For the purpose of message receiving, one could connect to a POP3 server. The purpose of the POP3 protocol is to allow a user to fetch a message to the client's computer and delete it from server. The well known port 110 is assigned for the unencrypted communication. It requires username and password for the authentication.
So, let's assume that there is an email POP3 server at smtp.server.com
and port
110
, which has the account mailio@server.com
created with the password
mailiopass
. The non-encrypted connection is created by using the class pop3
.
Authentication beside the username and password requires also the authentication type as third parameter, currently there is only
one method supported. To fetch a message, the method pop3::fetch
is being used. The first argument is the
id of a message to fetch, while the second is a message
instance to be populated with the fetched data:
try
{
pop3 conn("pop3.server.com", 110);
conn.authenticate("mailio@server.com", "mailiopass", pop3::auth_method_t::LOGIN);
message msg;
conn.fetch(1, msg);
}
catch (pop3_error& exc)
{
cout << exc.what() << endl;
}
catch (dialog_error& exc)
{
cout << exc.what() << endl;
}
The possible exceptions are on the POP3 level handled with pop3_error
and on the TCP level
with dialog_error
.