summaryrefslogtreecommitdiff
path: root/src/lib/email.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-02-16 00:52:53 +0100
committerCarl Hetherington <cth@carlh.net>2025-02-17 00:30:55 +0100
commite9167bc88529bf5eb71bdefa4e69fdbac790a391 (patch)
treefee677aa0457c07a7ef4677defaebc23ece3da28 /src/lib/email.cc
parent410624e0548f65b795b192367f9272eb6f5d7bdb (diff)
Add retry for email sending (#2963).2963-retry-email
Diffstat (limited to 'src/lib/email.cc')
-rw-r--r--src/lib/email.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/email.cc b/src/lib/email.cc
index 028624c69..f0ff9f910 100644
--- a/src/lib/email.cc
+++ b/src/lib/email.cc
@@ -21,6 +21,7 @@
#include "compose.hpp"
#include "config.h"
+#include "dcpomatic_log.h"
#include "email.h"
#include "exceptions.h"
#include "util.h"
@@ -110,6 +111,25 @@ Email::get_data(void* ptr, size_t size, size_t nmemb)
void
+Email::send_with_retry(string server, int port, EmailProtocol protocol, int retries, string user, string password)
+{
+ int this_try = 0;
+ while (true) {
+ try {
+ send(server, port, protocol, user, password);
+ return;
+ } catch (NetworkError& e) {
+ LOG_ERROR("Error %1 when trying to send email on attempt %2 of 3", e.what(), this_try + 1, retries);
+ if (this_try == (retries - 1)) {
+ throw;
+ }
+ }
+ ++this_try;
+ }
+}
+
+
+void
Email::send(string server, int port, EmailProtocol protocol, string user, string password)
{
_email = "Date: " + rfc_2822_date(time(nullptr)) + "\r\n"