Menu

SMTPS Authentication failed on GMail

Help
Anonymous
2010-04-10
2013-04-25
  • Anonymous

    Anonymous - 2010-04-10

    I do this to load my certificate:

    vmime::ref < vmime::security::cert::X509Certificate > loadX509CertificateFromFile( const std::string &path )
    {
            std::ifstream certFile;
            certFile.open( path.c_str(), std::ios::in | std::ios::binary );
            vmime::utility::inputStreamAdapter is ( certFile );
            vmime::ref < vmime::security::cert::X509Certificate > cert;
            cert = vmime::security::cert::X509Certificate::import( is );
            if ( cert != NULL )
                return cert;   
    }
    [/code/
    And then later on I do this to connect to send my mail:[code]
        ...
            vmime::ref < vmime::security::cert::defaultCertificateVerifier > vrf = vmime::create < vmime::security::cert::defaultCertificateVerifier >();
            std::vector < vmime::ref < vmime::security::cert::X509Certificate > > rootCAs;
            rootCAs.push_back( loadX509CertificateFromFile( "Thawte_Premium_Server_CA.pem" ) );
            vrf->setX509RootCAs( rootCAs );
            m_vmASession = vmime::create< vmime::net::session >();
            vmime::utility::url url("smtps://smtp.gmail.com");
            vmime::ref < vmime::net::transport > tr = m_vmASession->getTransport( url );
            tr->setCertificateVerifier( vrf );
            m_vmASession->getProperties()[ "transport.smtp.auth.username" ] = ui->lineEdit_setUser->text().toAscii().data();
            m_vmASession->getProperties()[ "transport.smtp.auth.password" ] = ui->lineEdit_setPass->text().toAscii().data();
            tr->setProperty( "transport.smtp.options.need-authentication", true );
            tr->setProperty( "options.need-authentication", true );
            tr->setProperty( "auth.username", ui->lineEdit_setUser->text().toAscii().data() );
            tr->setProperty( "auth.pass", ui->lineEdit_setPass->text().toAscii().data() );
            tr->setProperty( "server.port", 465 );
            tr->connect();
            tr->send( vmConstructedMessage );
            tr->disconnect();
        ...
    [/code]
    But it returns a vmime exception at tr->connect() : "Authentication error." From what I understand, when I connect through port 465 on smtp.gmail.com I use classical ssl/tls ( no starttls, no sasl ) I've tried forcing sasl, adding @gmail.com to the end of my username, and encoding my creds in base64 like I would if I was running AUTH LOGIN through openssl from a terminal. What am I doing wrong? 
    I'm using QT C++ on Linux.  Thanks a million!
    
     
  • Anonymous

    Anonymous - 2010-04-10

    Er, it's better formatted here on pastebin:

    http://pastebin.com/GKrmhHyr

    Thanks again in advance!

     
  • Vincent Richard

    Vincent Richard - 2010-04-10

    Hello,

    vmime::utility::url url("smtp://smtp.gmail.com");  // <== SMTP and not SMTP"S"
    vmime::ref <vmime::net::transport> tr = session->getTransport(url);
    tr->setProperty("connection.tls", true);  // <== You missed this
    tr->setProperty("auth.username", "login");
    tr->setProperty("auth.password", "password");
    tr->setProperty("options.need-authentication", true);
    tr->setCertificateVerifier(vrf);

    Best regards,

    Vincent

     
  • Anonymous

    Anonymous - 2010-04-10

    Now it just hangs when it reaches tr->connect() .

    For some reason I thought that you only had to use STARTTLS if you connected through port 587 ( I could be completely wrong, got that from here: http://mail.google.com/support/bin/answer.py?hl=en&answer=13287

     
  • Vincent Richard

    Vincent Richard - 2010-04-10

    Hang? Could you be more precise?

     
  • Anonymous

    Anonymous - 2010-04-10

    The application stops responding to user input and the window doesn't redraw when it is resized or something moves on top of it.

    Like it's in an infinite loop or something.

     
  • Vincent Richard

    Vincent Richard - 2010-04-11

    Hello,

    Could you post a full working example to reproduce the problem?
    *BE SURE TO REMOVE YOUR CREDENTIALS (EMAIL+PASSWORD) FROM YOUR CODE*

    Vincent

     
  • Anonymous

    Anonymous - 2010-04-12

    Ok, here's what I've got:

    http://dl.dropbox.com/u/1494123/VMimeAttempt.cpp

    And you probably already have the Thawte Premium Server CA, but here it is anyway:

    http://dl.dropbox.com/u/1494123/Thawte_Premium_Server_CA.pem

    I compiled it with `g++ thing.cpp  -L/usr/lib -lutil -lvmime` using g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1

     
  • Anonymous

    Anonymous - 2010-04-13

    Hey! I was playing around with the code that I posted and changed the port from 465 to 587 ( Which, according to the gmail help center I also linked to, uses starttls. ) and it sends email fine now. (c:

    I've also changed VMimeAttempt.cpp so that it works.

    Thanks.

     
  • Ali Majdzadeh

    Ali Majdzadeh - 2010-06-27

    Hello
    I am not sure whether you are tracing this post or not, but I have some problems regarding sending e-mail using Gmail. I used the test program presented here, but I get "cannot verify certificate against trusted certificates." I have followed the instructions mentioned in the vmime-book and accordingly altered the test program, but nothing changed.

     
  • Jorge Corredera

    Jorge Corredera - 2010-08-15

    Hi I am executing this code and I obtain :
    Cannot verify certificate against trusted certificates.

            vmASession->getProperties() = "aa@gmail.com";
            vmASession->getProperties() = "bb";
            tr->setProperty( "auth.username", "aa@gmail.com" );
            tr->setProperty( "auth.pass", "bb" );

    I have changed it like this. Some ideas ?

     
  • Vincent Richard

    Vincent Richard - 2010-08-17

    Hello,

    Have a look at this post:
    http://www.vmime.org/post/Connecting-to-GMail-SMTP

    Regards,

    Vincent

     
  • Jorge Corredera

    Jorge Corredera - 2010-08-18

    Hi:

    Thank you for your answer, I think the poblem is related with the gnutls library (2.2.4) . Should it work with this library or Do I need to install the newest one?.
    I have a problem Installing the newest one (that is in the post of compaling http://sourceforge.net/projects/vmime/forums/forum/237357/topic/3413715/index/page/2) . Could the error come from the use of this library?

    Regards,

    Jorge.

     
  • rubins tom

    rubins tom - 2010-10-03

    Hi,

        I am trying to run "VMimeAttempt.cpp" after setting up vmime on windows vista from the link <http://dl.dropbox.com/u/1494123/VMimeAttempt.cpp>. But when I run it I get the following erro message:

    "Cannot verify certificate against trusted certificates".

      Where could I be wrong? I have placed the "Thawte_Premium_Server_CA.pem" from < http://dl.dropbox.com/u/1494123/Thawte_Premium_Server_CA.pem> in the same folder as where the generated exe file is.

    Thanks in advance.

     
  • Vincent Richard

    Vincent Richard - 2010-10-03

    Hello!

    Putting the PEM files in the executable directory is not sufficient: please have a look at section "6.7.3    Certificate verification" of the VMime book (go to http://www.vmime.org/pages/Documentation ).

    Vincent

     
  • Dheeraj  Chugh

    Dheeraj Chugh - 2011-01-13

    I have tried the same code but tr-> connect always hangs, on further investigation i have found that the following call (window socket.cpp line number 94) is failing it "GetLastError" returns 10060 connection time out error.

    For reference following is the code snippet i am using, I have also tried with  example -6 but the result was same

    >>
    if (::connect(m_desc, reinterpret_cast <sockaddr*>(&addr), sizeof(addr)) == -1)
    {
    long err = GetLastError()

    >>

    vmime::ref < vmime::security::cert::X509Certificate > loadX509CertificateFromFile( const std::string &path )
    {

        try
        {
            std::ifstream certFile;
    certFile.open( path.c_str(), std::ios::in | std::ios::binary );
            vmime::utility::inputStreamAdapter is ( certFile );
            vmime::ref < vmime::security::cert::X509Certificate > cert;
            cert = vmime::security::cert::X509Certificate::import( is );
            if ( cert != NULL )
    return cert;
        }
        catch( vmime::exception &e )
        {
            std::cout << e.what();
        }
        catch( std::exception &e )
        {
            std::cout << e.what();
        }
    }

    int _tmain(int argc, _TCHAR* argv)
    {

    // VMime initialization
    vmime::platform::setHandler<vmime::platforms::windows::windowsHandler>();
        vmime::messageBuilder vmMessage;
        vmime::ref < vmime::plainTextPart >  vmTextPart;
        vmime::ref < vmime::net::session > vmASession;
        vmime::ref < vmime::security::cert::X509Certificate > loadX509CertificateFromFile( const std::string &path );
        try
        {
            vmMessage.setSubject( vmime::text("test 123") );
            vmMessage.setExpeditor( vmime::mailbox( "dchugh@adobe.com" ) );
            vmMessage.getRecipients().removeAllAddresses();
            vmMessage.getRecipients().appendAddress( vmime::create< vmime::mailbox >( "dheerajchugh1@example" ) );
            vmMessage.getTextPart()->setCharset( vmime::charsets::UTF_8 );
            vmMessage.getTextPart()->setText( vmime::create< vmime::stringContentHandler>( "Hey, somePerson, I'm trying to learn the vmime library." ) );
            vmime::ref < vmime::message > vmConstructedMessage = vmMessage.construct();
            vmime::utility::outputStreamAdapter out( std::cout );
            vmConstructedMessage->generate( out );
            std::cout << std::endl;
            vmime::ref < vmime::security::cert::defaultCertificateVerifier > vrf = vmime::create < vmime::security::cert::defaultCertificateVerifier >();
            std::vector < vmime::ref < vmime::security::cert::X509Certificate > > rootCAs;
            rootCAs.push_back( loadX509CertificateFromFile( "Thawte_Premium_Server_CA.pem" ) );
            vrf->setX509RootCAs( rootCAs );
            vmASession = vmime::create< vmime::net::session >();
            vmime::utility::url url("smtp://smtp.gmail.com");
            vmime::ref < vmime::net::transport > tr = vmASession->getTransport( url );
            tr->setCertificateVerifier( vrf );
            tr->setProperty( "connection.tls", true );
            //tr->setProperty( "connection.tls.required", true );
            //tr->setProperty( "options.sasl.fallback", true );
            //vmASession->getProperties() = "dheerajchugh303";
            //vmASession->getProperties() = "XXXXXXXXXX";
    //tr->setProperty( "transport.smtp.options.need-authentication", true );
            tr->setProperty( "options.need-authentication", true );
            tr->setProperty( "auth.username", "dheerajchugh303" );
            tr->setProperty( "auth.pass", "XXXXXXXX" );
            tr->setProperty( "server.port", 587 );
            tr->connect();
            tr->send( vmConstructedMessage );
            tr->disconnect();
            }
            catch( vmime::exception &e )
            {
                std::cout << e.what() << std::endl;
                return -1;
            }
            catch( std::exception &e )
            {
                std::cout << e.what() << std::endl;
                return -1;
            }
    return 0;
    }

    Platform : Windows -XP

     
  • Raphaël Vandon

    Raphaël Vandon - 2011-09-30

    Hello,
    first, I had some problems with authentication, so I decided to put them aside for now, using a class that accepts every certificate :

    class BlindCertificateAccepter : public vmime::security::cert::certificateVerifier {
    public : void verify(vmime::ref<vmime::security::cert::certificateChain> certs) {} };
    

    Which might help some people coming here.

    Now, I am having an error when I try do send a mail ; the code :

            transport   = session->getTransport (vmime::utility::url("smtp://smtp.gmail.com"));
            transport->setProperty("options.need−authentication", true);
            transport->setProperty("connection.tls", true);
            transport->setProperty("auth.username", "me@gmail.com");
            transport->setProperty("auth.password", "my_password");
            transport->setCertificateVerifier(vmime::create<BlindCertificateAccepter>());
            transport->connect();
            ...
            transport->send(msg);
    

    And I get a vmime::exceptions::command_error at the last line, with this response (in e.response()) :

    5.5.1 Authentication Required. Learn more at
    5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257

    followed by some symbols.
    I tried of course their captcha unlocker for the same result. Anyone having a similar problem ?

    PS : I'm NOT logged in on the gmail imap server, I just try to send mail. Could this be the issue ?
    PPS : vmime 9.0

     

Log in to post a comment.