diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-15 13:19:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-15 13:19:20 +0200 |
commit | 3c43330dddcd71c3251a55d5211edf506d3ec767 (patch) | |
tree | 0000a85f2a0b73727fd6dc7d7ca3e58fbd687496 /examples | |
parent | b91aedf79c3bb5b803ec9a335baab385a19cbbbc (diff) | |
download | sink-3c43330dddcd71c3251a55d5211edf506d3ec767.tar.gz sink-3c43330dddcd71c3251a55d5211edf506d3ec767.zip |
Fix smtps over port 465
465 is for tls only
587 is for plain with upgrade via starttls
curl recognizes tls by a smtps:// protocol,
for start tls we must start with smtp:// but set the flag to upgrade.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/mailtransportresource/mailtransport.cpp | 22 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransport.h | 3 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 6 |
3 files changed, 23 insertions, 8 deletions
diff --git a/examples/mailtransportresource/mailtransport.cpp b/examples/mailtransportresource/mailtransport.cpp index ce24d7f..c455b7c 100644 --- a/examples/mailtransportresource/mailtransport.cpp +++ b/examples/mailtransportresource/mailtransport.cpp | |||
@@ -83,7 +83,7 @@ CurlVersionInfo getVersionInfo() | |||
83 | bool sendMessageCurl(const char *to[], int numTos, | 83 | bool sendMessageCurl(const char *to[], int numTos, |
84 | const char *cc[], int numCcs, | 84 | const char *cc[], int numCcs, |
85 | const char *msg, | 85 | const char *msg, |
86 | bool useTls, | 86 | bool useStarttls, |
87 | const char* from, | 87 | const char* from, |
88 | const char *username, const char *password, | 88 | const char *username, const char *password, |
89 | const char *server, bool verifyPeer, const QByteArray &cacert, QByteArray &errorMessage, | 89 | const char *server, bool verifyPeer, const QByteArray &cacert, QByteArray &errorMessage, |
@@ -107,7 +107,7 @@ bool sendMessageCurl(const char *to[], int numTos, | |||
107 | 107 | ||
108 | curl_easy_setopt(curl, CURLOPT_URL, server); | 108 | curl_easy_setopt(curl, CURLOPT_URL, server); |
109 | 109 | ||
110 | if (useTls) { | 110 | if (useStarttls) { |
111 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); | 111 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); |
112 | } | 112 | } |
113 | 113 | ||
@@ -186,6 +186,7 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
186 | ccList << mb.address(); | 186 | ccList << mb.address(); |
187 | } | 187 | } |
188 | const bool verifyPeer = options.testFlag(VerifyPeers); | 188 | const bool verifyPeer = options.testFlag(VerifyPeers); |
189 | const bool useStarttls = options.testFlag(UseStarttls); | ||
189 | const bool useTls = options.testFlag(UseTls); | 190 | const bool useTls = options.testFlag(UseTls); |
190 | 191 | ||
191 | const int numTos = toList.size(); | 192 | const int numTos = toList.size(); |
@@ -199,12 +200,21 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
199 | for (int i = 0; i < numCcs; i++) { | 200 | for (int i = 0; i < numCcs; i++) { |
200 | cc[i] = ccList.at(i); | 201 | cc[i] = ccList.at(i); |
201 | } | 202 | } |
202 | //Because curl will fail with smtps, but it won't tell you why. | ||
203 | auto serverAddress = server; | 203 | auto serverAddress = server; |
204 | serverAddress.replace("smtps://", "smtp://"); | 204 | if (serverAddress.startsWith("smtps://")) { |
205 | serverAddress = serverAddress.mid(8); | ||
206 | } | ||
207 | if (serverAddress.startsWith("smtp://")) { | ||
208 | serverAddress = serverAddress.mid(7); | ||
209 | } | ||
210 | if (useStarttls) { | ||
211 | serverAddress = "smtp://" + serverAddress; | ||
212 | } else if (useTls) { | ||
213 | serverAddress = "smtps://" + serverAddress; | ||
214 | } | ||
205 | 215 | ||
206 | const auto versionInfo = getVersionInfo(); | 216 | const auto versionInfo = getVersionInfo(); |
207 | if (useTls && !versionInfo.supportsSsl) { | 217 | if ((useTls || useStarttls) && !versionInfo.supportsSsl) { |
208 | qCWarning(mailtransportCategory) << "libcurl built without ssl support: " << versionInfo.info; | 218 | qCWarning(mailtransportCategory) << "libcurl built without ssl support: " << versionInfo.info; |
209 | } | 219 | } |
210 | 220 | ||
@@ -212,7 +222,7 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
212 | QByteArray errorMessage; | 222 | QByteArray errorMessage; |
213 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, | 223 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, |
214 | message->encodedContent(), | 224 | message->encodedContent(), |
215 | useTls, | 225 | useStarttls, |
216 | from.isEmpty() ? nullptr : from, | 226 | from.isEmpty() ? nullptr : from, |
217 | username, password, | 227 | username, password, |
218 | serverAddress, verifyPeer, cacert, | 228 | serverAddress, verifyPeer, cacert, |
diff --git a/examples/mailtransportresource/mailtransport.h b/examples/mailtransportresource/mailtransport.h index 0fa5a66..0f53c2b 100644 --- a/examples/mailtransportresource/mailtransport.h +++ b/examples/mailtransportresource/mailtransport.h | |||
@@ -27,7 +27,8 @@ namespace MailTransport | |||
27 | { | 27 | { |
28 | enum Option { | 28 | enum Option { |
29 | UseTls = 1, | 29 | UseTls = 1, |
30 | VerifyPeers = 2 | 30 | UseStarttls = 2, |
31 | VerifyPeers = 4 | ||
31 | }; | 32 | }; |
32 | Q_DECLARE_FLAGS(Options, Option); | 33 | Q_DECLARE_FLAGS(Options, Option); |
33 | 34 | ||
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 10d94bc..9163d3b 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -127,7 +127,11 @@ public: | |||
127 | } else { | 127 | } else { |
128 | MailTransport::Options options; | 128 | MailTransport::Options options; |
129 | if (settings.server.contains("smtps")) { | 129 | if (settings.server.contains("smtps")) { |
130 | options |= MailTransport::UseTls; | 130 | if (settings.server.contains("465")) { |
131 | options |= MailTransport::UseTls; | ||
132 | } else { | ||
133 | options |= MailTransport::UseStarttls; | ||
134 | } | ||
131 | } | 135 | } |
132 | 136 | ||
133 | SinkLog() << "Sending message " << settings.server << settings.username << "CaCert: " << settings.cacert << "Using tls: " << bool(options & MailTransport::UseTls); | 137 | SinkLog() << "Sending message " << settings.server << settings.username << "CaCert: " << settings.cacert << "Using tls: " << bool(options & MailTransport::UseTls); |