Closed opengpu closed 2 years ago
It is up to anyone according to usage mode, for me following worked well ` void SmtpNotifier::notify(QString message) { // do not block main thread sending the mail auto result = QtConcurrent::run(sendMail, this, m_smtpServer, m_smtpPort, m_recipients, message); Q_UNUSED(result); }
void SmtpNotifier::sendMail(SmtpNotifier *notifier, QString server, uint port, QStringList recipients, QString message) { SmtpClient smtp(server, port, SmtpClient::TcpConnection);
connect(&smtp, &SmtpClient::smtpError, notifier, &SmtpNotifier::handleSmtpError);
const auto theSender = QString{"sender@mydomain.com"};
smtp.setUser(theSender);
smtp.setConnectionTimeout(std::chrono::seconds(30));
smtp.setResponseTimeout(std::chrono::seconds(30));
smtp.setAuthMethod(SmtpClient::AuthLogin);
// smtp.setPassword(); // no password when inside of companmy network
MimeMessage mimeMsg;
mimeMsg.setSender(EmailAddress(theSender, tr("my application")));
for (const auto &recipientAddress : recipients)
{
mimeMsg.addRecipient(EmailAddress(recipientAddress));
}
mimeMsg.setSubject("Value threshold exceeded");
MimeText text;
text.setText(message + "\r\n\r\n" + tr("Your application"));
mimeMsg.addPart(&text);
smtp.connectToHost();
smtp.login();
smtp.sendMail(mimeMsg);
smtp.quit();
} `
Slowest part is usually(!) the sendMail()
bit, as most of the data transfer happens here.
An Asynchronous mode is added in v2.0
of the library.
which step is the slowest? why don't u make it ASync?