From 29a964d5b771f29dfa918b95321bd01452b44486 Mon Sep 17 00:00:00 2001 From: Emil M George Date: Fri, 10 Jun 2022 11:32:51 +0530 Subject: [PATCH] Add support for custom SMTP ports The port can be optionally specified by appending `:` to the existing SMTP Server field in settings. If no port is specified, then the default port (25 for insecure or 465 for SSL) is used. Closes #12212. PR #17157. --- src/base/net/smtp.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/base/net/smtp.cpp b/src/base/net/smtp.cpp index 7476d4460..ab105e89e 100644 --- a/src/base/net/smtp.cpp +++ b/src/base/net/smtp.cpp @@ -47,6 +47,7 @@ #include "base/global.h" #include "base/logger.h" #include "base/preferences.h" +#include "base/utils/string.h" namespace { @@ -163,16 +164,20 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje } // Connect to SMTP server + const QStringList serverEndpoint = pref->getMailNotificationSMTP().split(u':'); + const QString serverAddress = serverEndpoint[0]; + const std::optional serverPort = Utils::String::parseInt(serverEndpoint.value(1)); + #ifndef QT_NO_OPENSSL if (pref->getMailNotificationSMTPSSL()) { - m_socket->connectToHostEncrypted(pref->getMailNotificationSMTP(), DEFAULT_PORT_SSL); + m_socket->connectToHostEncrypted(serverAddress, serverPort.value_or(DEFAULT_PORT_SSL)); m_useSsl = true; } else { #endif - m_socket->connectToHost(pref->getMailNotificationSMTP(), DEFAULT_PORT); + m_socket->connectToHost(serverAddress, serverPort.value_or(DEFAULT_PORT)); m_useSsl = false; #ifndef QT_NO_OPENSSL }