I try to send automatic emails from a Qt application if a user creates a new incident. Obviously, the purpose is to warn other people about this incident.
My problem is actually to send the email. I found this library of BlueTiger9. It's an email sender which seems to work but unfortunately not for me, and I'm currently facing to an issue that I cannot explain.
I put the following parts of my code that I assume will help to define what's going wrong. If anything more is needed, just let me know.
In my .pro file:
LIBS += -L$$PWD/ -lSMTPEmail
I included a file that includes all the other headers and I added all the headers of the library in my project too.
#ifndef SMTPMIME_H
#define SMTPMIME_H
#include "smtpclient.h"
#include "mimepart.h"
#include "mimehtml.h"
#include "mimeattachment.h"
#include "mimemessage.h"
#include "mimetext.h"
#include "mimeinlinefile.h"
#include "mimefile.h"
#endif // SMTPMIME_H
In each header included, there is another inclusion of the following code:
#ifndef SMTPEXPORTS_H
#define SMTPEXPORTS_H
#ifdef SMTP_BUILD
#define SMTP_EXPORT Q_DECL_EXPORT
#else
#define SMTP_EXPORT Q_DECL_IMPORT
#endif
#endif // SMTPEXPORTS_H
Then I just tried to use the example of sending a simple email (I just added the proxy settings):
SmtpClient smtp("smtp.office365.com", 587, SmtpClient::TlsConnection);
smtp.setUser("USER_Off365");
smtp.setPassword("PASSWORD_Off365");
smtp.setAuthMethod(SmtpClient::AuthLogin);
QNetworkProxy proxy(QNetworkProxy::HttpProxy, "PROXY_ADD", PROXY_PORT, "PROXY_USER", "PROXY_PW");
smtp.getSocket()->setProxy(proxy);
MimeMessage message;
message.setSender(new EmailAddress("MY_ADDRESS", "MY_NAME"));
message.addRecipient(new EmailAddress("ADDRESS_TO", "A_NAME"));
message.setSubject("Subject");
MimeText text;
text.setText("Test");
message.addPart(&text);
if(smtp.connectToHost()){
if(smtp.login()){
if(smtp.sendMail(message)){
smtp.quit();
}
}
}
But I am not able to connect to the SMTP server. The error that I received from the socket is "Error communicating with HTTP Proxy"
Trying with an Internet connection from my phone, I am able to go to the next step but I still have a problem of authentication.
Just in case, I need to use Office365 SMTP server and the settings to connect to it are available on this page. (smtp.office365.com / 587 explicit / TLS v1-1.2)
If anyone has any idea which could help, it would be really appreciated!