Advertisement
Guest User

Klaus Fiedler

a guest
Apr 9th, 2010
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. /*
  2. I do this to load my certificate:
  3. */
  4.  
  5. vmime::ref < vmime::security::cert::X509Certificate > loadX509CertificateFromFile( const std::string &path )
  6. {
  7.         std::ifstream certFile;
  8.         certFile.open( path.c_str(), std::ios::in | std::ios::binary );
  9.         vmime::utility::inputStreamAdapter is ( certFile );
  10.         vmime::ref < vmime::security::cert::X509Certificate > cert;
  11.         cert = vmime::security::cert::X509Certificate::import( is );
  12.         if ( cert != NULL )
  13.             return cert;  
  14. }
  15.  
  16. /*
  17. And then later on I do this to connect to send my mail:
  18. */
  19.  
  20.     ...
  21.         vmime::ref < vmime::security::cert::defaultCertificateVerifier > vrf = vmime::create < vmime::security::cert::defaultCertificateVerifier >();
  22.         std::vector < vmime::ref < vmime::security::cert::X509Certificate > > rootCAs;
  23.         rootCAs.push_back( loadX509CertificateFromFile( "Thawte_Premium_Server_CA.pem" ) );
  24.         vrf->setX509RootCAs( rootCAs );
  25.         m_vmASession = vmime::create< vmime::net::session >();
  26.         vmime::utility::url url("smtps://smtp.gmail.com");
  27.         vmime::ref < vmime::net::transport > tr = m_vmASession->getTransport( url );
  28.         tr->setCertificateVerifier( vrf );
  29.         m_vmASession->getProperties()[ "transport.smtp.auth.username" ] = ui->lineEdit_setUser->text().toAscii().data();
  30.         m_vmASession->getProperties()[ "transport.smtp.auth.password" ] = ui->lineEdit_setPass->text().toAscii().data();
  31.         tr->setProperty( "transport.smtp.options.need-authentication", true );
  32.         tr->setProperty( "options.need-authentication", true );
  33.         tr->setProperty( "auth.username", ui->lineEdit_setUser->text().toAscii().data() );
  34.         tr->setProperty( "auth.pass", ui->lineEdit_setPass->text().toAscii().data() );
  35.         tr->setProperty( "server.port", 465 );
  36.         tr->connect();
  37.         tr->send( vmConstructedMessage );
  38.         tr->disconnect();
  39.     ...
  40.  
  41. /*
  42. 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?
  43. I'm using QT C++ on Linux.  Thanks a million!
  44. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement