Leosac  0.8.0
Open Source Access Control
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 }
Leosac::Module::SMTP::SMTPModule
Definition: SMTPModule.hpp:43
WARN
@ WARN
Definition: log.hpp:33
Leosac::Module::SMTP
Definition: SMTPAudit.cpp:32
Leosac::Module::SMTP::SMTPServiceImpl::SMTPServiceImpl
SMTPServiceImpl(SMTPModule &)
Definition: SMTPServiceImpl.cpp:27
Leosac::Module
All modules that provides features to Leosac shall be in this namespace.
Leosac::MailInfo
Definition: Mail.hpp:30
Leosac::Module::SMTP::SMTPServiceImpl::async_send_to_admin
virtual void async_send_to_admin(const MailInfo &mail) override
Similar to send, but add the leosac administrator email to the recipients' list.
Definition: SMTPServiceImpl.cpp:37
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
SMTPModule.hpp
Leosac::Module::SMTP::SMTPModule::async_send_mail
void async_send_mail(const MailInfo &mail)
Asynchronously and thread-safely send an email.
Definition: SMTPModule.cpp:425
Leosac::Colorize::green
std::string green(const T &in)
Definition: Colorize.hpp:82
Leosac::Module::SMTP::SMTPServiceImpl::async_send
virtual void async_send(const MailInfo &mail) override
Send a message to the mailer service (if any) to enqueue an email.
Definition: SMTPServiceImpl.cpp:32
Leosac::Colorize::cyan
std::string cyan(const T &in)
Definition: Colorize.hpp:94
SMTPServiceImpl.hpp
Leosac::Module::SMTP::SMTPServiceImpl::smtp_
SMTPModule & smtp_
Definition: SMTPServiceImpl.hpp:41