I am trying to use the Poco library to send an email. Platform is OS X, Yosemite 10.10.2 I am using Qt 5.3 32 bit. I followed the official instructions from here, and since I am using 32 bit Qt, and want the libraries to be statically linked, I used ./configure --static --config=Darwin32
. And it installed in /usr/local
correctly, following which I linked the necessary libraries (PocoNet
and PocoFoundation
), and tried this following code, which I found here. What I am trying to do is send an email to my gmail account from my account itself:
#include "MailSender.hpp"
#include "Poco/Net/SMTPClientSession.h"
#include "Poco/Net/MailMessage.h"
#include <iostream>
#include <QDebug>
using namespace Poco::Net;
MailSender::MailSender()
{
try
{
MailMessage msg;
msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
"my email id",
"Some name"));
msg.setSender ("<myname> <my email id>");
msg.setSubject ("some subject");
msg.setContent ("Sending mail from C++ using POCO C++ Libraries");
SMTPClientSession smtp ("smtp.gmail.com"); // SMTP server name
smtp.login ("smtp.gmail.com",SMTPClientSession::AUTH_LOGIN,"my mail id","my_password");
smtp.sendMessage (msg);
smtp.close ();
qDebug() << "Sent << endl;
}
catch (std::exception &e)
{
qDebug() << "Damn!" << e.what() << endl;
}
}
However, I am getting a Damn! Connection refused message. Any idea how do I fix this?
Edit: I found that SecureSMTPClientSession
is recommended for secure login. However, I don't find any such header file in Poco/Net
. What I did is ./configure --static --config=Darwin32
, followed by make -s
and then make -s install
. Then I found the static libraries and includes in /usr/local
..
Aucun commentaire:
Enregistrer un commentaire