41 #include "mimemessage.h"
43 #include "smtpclient.h"
50 return global_instance;
56 instance().sendAlarmNotification_internal ( std::move ( alarms ) );
58 catch ( std::exception& e )
60 std::cerr <<
"Exception in e-mail sending procedure: " << e.what() << std::endl;
64 std::cerr <<
"Unknown error in e-mail sending procedure: " << std::endl;
83 SmtpClient::TcpConnection
87 QString::fromUtf8 (
"Alarm Notification Daemon" )
89 EmailAddress recipient (
91 QString::fromUtf8 (
"Alarm Notification Mailing List" )
94 email.setSender ( &sender );
95 email.addTo ( &recipient );
96 email.setSubject (
"Detector Control System Alarm" );
98 text.setEncoding(MimePart::QuotedPrintable);
99 text.setCharset(QString::fromUtf8(
"utf8"));
101 email.addPart ( &text );
103 std::cout <<
"Sending alarm notification by e-mail!" << std::endl;
104 const bool connection = smtp.connectToHost();
107 QString errormessage = QString::fromUtf8 (
"An error occured while connecting to the SMTP server.\n" );
108 errormessage +=
"Server response: " + smtp.getResponseCode() + QString::fromUtf8 (
" " ) + smtp.getResponseText();
109 std::string stderrormessage ( errormessage.toUtf8().data() );
110 throw std::runtime_error ( stderrormessage );
112 const bool sending = smtp.sendMail(email);
115 QString errormessage = QString::fromUtf8 (
"An error occured while sending the e-mail.\n" );
116 errormessage +=
"Server response: " + smtp.getResponseCode() + QString::fromUtf8 (
" " ) + smtp.getResponseText();
117 std::string stderrormessage ( errormessage.toUtf8().data() );
118 throw std::runtime_error ( stderrormessage );
126 text += QString::fromUtf8 (
"Hello,\n\nthe following PV(s) triggered an alarm:\n\n" );
127 for (
auto i = alarms.begin(); i != alarms.end(); i++ )
129 text+= QString::fromUtf8 ( ( *i ).getPVName().c_str() ) + QString::fromUtf8 (
"\n" );
131 text += QString::fromUtf8 (
"\nPlease remember to acknowledge the alarms if you go solving the problem.\n\n\nYour Alarm Notification Service\n" );
static EMailSender & instance() noexcept
Get singleton instance.
~EMailSender()
Destructor.
Send alarm notifications via e-mail.
QString composeMessageText(const std::vector< AlarmStatusEntry > &alarms)
Compose message text.
EMailSender()
Constructor.
Namespace for Alarm Notifications application.
static void sendAlarmNotification(const std::vector< AlarmStatusEntry > alarms) noexcept
Send an alarm notification via e-mail.
#define noexcept
Allow using the noexcept keyword with GCC < 4.6.
Send alarm notifications via e-mail.
Singleton to read and change the configuration of this application.
void sendAlarmNotification_internal(const std::vector< AlarmStatusEntry > alarms)
Compose and send the e-mail notification.
static AlarmConfiguration & instance() noexcept
Get singleton instance.