summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-17 15:28:04 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-03-17 15:28:04 +0100
commitf4cba9977d46bd94b19586e31f1bea250f211c0c (patch)
treef202479ef41798d4b13da2cb07293371030458c4 /examples
parenteecf234e4fc79320fc74f2e917b9e9777f0761af (diff)
downloadsink-f4cba9977d46bd94b19586e31f1bea250f211c0c.tar.gz
sink-f4cba9977d46bd94b19586e31f1bea250f211c0c.zip
Gather some more error messages when trying to send mail.
Diffstat (limited to 'examples')
-rw-r--r--examples/mailtransportresource/mailtransport.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/examples/mailtransportresource/mailtransport.cpp b/examples/mailtransportresource/mailtransport.cpp
index 8e18203..985ebcc 100644
--- a/examples/mailtransportresource/mailtransport.cpp
+++ b/examples/mailtransportresource/mailtransport.cpp
@@ -70,7 +70,7 @@ static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow
70} 70}
71 71
72 72
73bool sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs, const char *msg, bool useTls, const char* from, const char *username, const char *password, const char *server, bool verifyPeer, const QByteArray &cacert) 73bool sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs, const char *msg, bool useTls, const char* from, const char *username, const char *password, const char *server, bool verifyPeer, const QByteArray &cacert, QByteArray &errorMessage)
74{ 74{
75 CURL *curl; 75 CURL *curl;
76 CURLcode res = CURLE_OK; 76 CURLcode res = CURLE_OK;
@@ -129,11 +129,20 @@ bool sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs,
129 129
130 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); 130 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
131 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback); 131 curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
132 char errorBuffer[CURL_ERROR_SIZE];
133 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
132 134
133 res = curl_easy_perform(curl); 135 res = curl_easy_perform(curl);
134 if(res != CURLE_OK) { 136 if(res != CURLE_OK) {
135 fprintf(stderr, "curl_easy_perform() failed: %s\n", 137 errorMessage += curl_easy_strerror(res);
136 curl_easy_strerror(res)); 138 errorMessage += "; ";
139 }
140 long http_code = 0;
141 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
142 if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK) {
143 //Succeeded
144 } else {
145 errorMessage += errorBuffer;
137 } 146 }
138 curl_slist_free_all(recipients); 147 curl_slist_free_all(recipients);
139 curl_easy_cleanup(curl); 148 curl_easy_cleanup(curl);
@@ -178,5 +187,10 @@ bool MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteA
178 auto serverAddress = server; 187 auto serverAddress = server;
179 serverAddress.replace("smtps://", "smtp://"); 188 serverAddress.replace("smtps://", "smtp://");
180 189
181 return sendMessageCurl(to, numTos, cc, numCcs, msg, useTls, from.isEmpty() ? nullptr : from, username, password, serverAddress, verifyPeer, cacert); 190 QByteArray errorMessage;
191 auto ret = sendMessageCurl(to, numTos, cc, numCcs, msg, useTls, from.isEmpty() ? nullptr : from, username, password, serverAddress, verifyPeer, cacert, errorMessage);
192 if (!ret) {
193 SinkWarning() << "Failed to send message: " << errorMessage;
194 }
195 return ret;
182} 196}