karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3 and IMAP protocols. It is based on standard C++ 17 and Boost library.
Other
372 stars 98 forks source link

Switching to SSL failed #133

Closed Maurizio1 closed 1 year ago

Maurizio1 commented 1 year ago

Hi,

I'm using:

mailio::pop3s conn("pop3s.xxxxx.it", 995); conn.authenticate("myname@mydomain.it", "mypassword", mailio::pop3s::auth_method_t::LOGIN); to connect to mail server. I get the error: Caught exception while connecting: Switching to SSL failed.

Any advice on where to look, OpenSSl version, Boost library linker include, server configuration, etc...? (no SSL connection using mailio::pop3 on port 110 works as espected)

Thank you in advance!

Maurizio

karastojko commented 1 year ago

Are you sure that the hostname is like pop3s.xxxx.it? Usually the hostnames are like pop.gmail.com and pop.mail.yahoo.com (no S at the end of "pop"), while the port number (110 or 995) determines whether it is plain or SSL connection.

Maurizio1 commented 1 year ago

Thanks for the prompt reply. Yes, I'm sure, I also use the mailbox from Outlook.

karastojko commented 1 year ago

I do not know does your particular server support SSL login or STARTTLS or both. Can you please try with the STARTTLS option and check whether it works or not?

Maurizio1 commented 1 year ago

It's the server of my provider and it looks like it usese just SSL/TLS. Anyway I could not figure out how to make it working by using the STARTTLS option, but it worked like a charm with the following instructions: `mailio::pop3s conn("pop3s.myserver.it", 995);

        mailio::dialog_ssl::ssl_options_t ssl_options;

        ssl_options.method = boost::asio::ssl::context::tls_client;

        conn.ssl_options(ssl_options);

        std::string answer = conn.authenticate("myaccount@mydomain.it", "mypassword", mailio::pop3s::auth_method_t::LOGIN);`

Thank you very much for the library and your support.

Maurizio

karastojko commented 1 year ago

Interesting, do you have to set the same TLS optiom for SMTP and IMAP?

Maurizio1 commented 1 year ago

Did not try because I was interested just on POP3, but I will try and let you know...

Maurizio1 commented 1 year ago

Yes, I can confirm that for POP3, IMAP and SMTP I can successfully connect to mail server only if I set the ssl options:

    `mailio::dialog_ssl::ssl_options_t ssl_options;
     ssl_options.method = boost::asio::ssl::context::tls_client;
     ssl_options.verify_mode = boost::asio::ssl::verify_none;
     conn.ssl_options(ssl_options);`
karastojko commented 1 year ago

Thanks for the info.