Leosac  0.7.0
OpenSourceAccessControl
SMTPServiceImpl.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "SMTPServiceImpl.hpp"
21 #include "SMTPModule.hpp"
22 
23 using namespace Leosac;
24 using namespace Leosac::Module;
25 using namespace Leosac::Module::SMTP;
26 
28  : smtp_(m)
29 {
30 }
31 
33 {
34  smtp_.async_send_mail(mail);
35 }
36 
38 {
39  auto mail_copy = mail;
40  char *mail_addr = getenv("LEOSAC_ADMIN_MAIL");
41  if (mail_addr)
42  {
43  mail_copy.to.insert(mail_copy.to.begin(), std::string(mail_addr));
44  }
45  else
46  WARN("Failed to add administrator as a recipient for email titled "
47  << Colorize::cyan(mail_copy.title)
48  << " because no admin "
49  "email is configured. Please set the "
50  << Colorize::green("LEOSAC_ADMIN_MAIL") << " environment variable.");
51 
52  async_send(mail_copy);
53 }
virtual void async_send(const MailInfo &mail) override
Send a message to the mailer service (if any) to enqueue an email.
This is the header file for a generated source file, GitSHA1.cpp.
Definition: log.hpp:33
std::string green(const T &in)
Definition: Colorize.hpp:82
All modules that provides features to Leosac shall be in this namespace.
virtual void async_send_to_admin(const MailInfo &mail) override
Similar to send, but add the leosac administrator email to the recipients&#39; list.
std::string cyan(const T &in)
Definition: Colorize.hpp:94
void async_send_mail(const MailInfo &mail)
Asynchronously and thread-safely send an email.
Definition: SMTPModule.cpp:425