1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-09 06:17:58 +00:00

Add support for custom SMTP ports

The port can be optionally specified by appending `:<port>` 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.
This commit is contained in:
Emil M George 2022-06-10 11:32:51 +05:30 committed by GitHub
parent 5e6174c087
commit 29a964d5b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,7 @@
#include "base/global.h" #include "base/global.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/string.h"
namespace namespace
{ {
@ -163,16 +164,20 @@ void Smtp::sendMail(const QString &from, const QString &to, const QString &subje
} }
// Connect to SMTP server // Connect to SMTP server
const QStringList serverEndpoint = pref->getMailNotificationSMTP().split(u':');
const QString serverAddress = serverEndpoint[0];
const std::optional<int> serverPort = Utils::String::parseInt(serverEndpoint.value(1));
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
if (pref->getMailNotificationSMTPSSL()) if (pref->getMailNotificationSMTPSSL())
{ {
m_socket->connectToHostEncrypted(pref->getMailNotificationSMTP(), DEFAULT_PORT_SSL); m_socket->connectToHostEncrypted(serverAddress, serverPort.value_or(DEFAULT_PORT_SSL));
m_useSsl = true; m_useSsl = true;
} }
else else
{ {
#endif #endif
m_socket->connectToHost(pref->getMailNotificationSMTP(), DEFAULT_PORT); m_socket->connectToHost(serverAddress, serverPort.value_or(DEFAULT_PORT));
m_useSsl = false; m_useSsl = false;
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
} }