diff options
-rw-r--r-- | data/anope.example.conf | 2 | ||||
-rw-r--r-- | include/mail.h | 2 | ||||
-rw-r--r-- | src/mail.cpp | 20 |
3 files changed, 14 insertions, 10 deletions
diff --git a/data/anope.example.conf b/data/anope.example.conf index 6198c9776..f0e80597b 100644 --- a/data/anope.example.conf +++ b/data/anope.example.conf @@ -950,7 +950,7 @@ mail * If you are running on Windows you should use a Windows sendmail port * like https://www.glob.com.au/sendmail/ for sending emails. */ - sendmailpath = "/usr/sbin/sendmail -t" + sendmailpath = "/usr/sbin/sendmail -it" /* * This is the email address from which all the emails are to be sent from. diff --git a/include/mail.h b/include/mail.h index eeacd3842..b9bc1509b 100644 --- a/include/mail.h +++ b/include/mail.h @@ -26,6 +26,7 @@ namespace Mail : public Thread { private: + Anope::string error; Anope::string sendmail_path; Anope::string send_from; Anope::string mail_to; @@ -35,7 +36,6 @@ namespace Mail Anope::string content_type; bool dont_quote_addresses; - bool success = false; public: /** Construct this message. Once constructed call Thread::Start to launch the mail sending. * @param sf Config->SendFrom diff --git a/src/mail.cpp b/src/mail.cpp index 87a030668..762c889a5 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -28,18 +28,18 @@ Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, con Mail::Message::~Message() { - if (success) + if (error.empty()) Log(LOG_NORMAL, "mail") << "Successfully delivered mail for " << mail_to << " (" << addr << ")"; else - Log(LOG_NORMAL, "mail") << "Error delivering mail for " << mail_to << " (" << addr << ")"; + Log(LOG_NORMAL, "mail") << "Error delivering mail for " << mail_to << " (" << addr << "): " << error; } void Mail::Message::Run() { - FILE *pipe = popen(sendmail_path.c_str(), "w"); - + auto *pipe = popen(sendmail_path.c_str(), "w"); if (!pipe) { + error = strerror(errno); SetExitState(); return; } @@ -53,12 +53,16 @@ void Mail::Message::Run() fprintf(pipe, "Content-Type: %s\r\n", content_type.c_str()); fprintf(pipe, "Content-Transfer-Encoding: 8bit\r\n"); fprintf(pipe, "\r\n"); - fprintf(pipe, "%s", message.c_str()); - fprintf(pipe, "\r\n.\r\n"); - pclose(pipe); + std::stringstream stream(message.str()); + for (Anope::string line; std::getline(stream, line.str()); ) + fprintf(pipe, "%s\r\n", line.c_str()); + fprintf(pipe, "\r\n"); + + auto result = pclose(pipe); + if (result > 0) + error = "Sendmail exited with code " + Anope::ToString(result); - success = true; SetExitState(); } |