vmime::ref<vmime::security::cert::X509Certificate>loadX509CertificateFromFile(conststd::string&path){std::ifstreamcertFile;certFile.open(path.c_str(),std::ios::in|std::ios::binary);vmime::utility::inputStreamAdapteris(certFile);vmime::ref<vmime::security::cert::X509Certificate>cert;cert=vmime::security::cert::X509Certificate::import(is);if(cert!=NULL)returncert;}[/code/AndthenlateronIdothistoconnecttosendmymail:[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::urlurl("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]Butitreturnsavmimeexceptionattr->connect():"Authentication error."FromwhatIunderstand,whenIconnectthroughport465onsmtp.gmail.comIuseclassicalssl/tls(nostarttls,nosasl)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'musingQTC++onLinux.Thanksamillion!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I compiled it with `g++ thing.cpp -L/usr/lib -lutil -lvmime` using g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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".
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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()
I do this to load my certificate:
Er, it's better formatted here on pastebin:
http://pastebin.com/GKrmhHyr
Thanks again in advance!
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
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 )
Hang? Could you be more precise?
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.
Hello,
Could you post a full working example to reproduce the problem?
*BE SURE TO REMOVE YOUR CREDENTIALS (EMAIL+PASSWORD) FROM YOUR CODE*
Vincent
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
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.
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.
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 ?
Hello,
Have a look at this post:
http://www.vmime.org/post/Connecting-to-GMail-SMTP
Regards,
Vincent
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.
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.
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
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
Hello,
first, I had some problems with authentication, so I decided to put them aside for now, using a class that accepts every certificate :
Which might help some people coming here.
Now, I am having an error when I try do send a mail ; the code :
And I get a vmime::exceptions::command_error at the last line, with this response (in e.response()) :
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