def send_mail(subject,
              message,
              from_email,
              to_emails,
              reply_to_email=None,
              html_message=None,
              attachments=None):
    okmails = to_emails if settings.DEBUG is False else filter_whitelist_emails(
        to_emails)
    if len(okmails) > 0:
        msg = EmailMultiAlternatives(subject,
                                     message,
                                     from_email,
                                     bcc=okmails,
                                     reply_to=[reply_to_email])
        if html_message is not None:
            msg.attach_alternative(html_message, 'text/html')
        if attachments is None:
            attachments = []
        for attachment in attachments:
            msg.attach(attachment.name, attachment.read())
        print(('Mail sent to ' + ', '.join(okmails) +
               (', on whitelist' if settings.DEBUG else '')))
        mailer = import_string(Config.default_mailer())
        mailer.send(msg)
Exemple #2
0
 def send(self):
     # only send to whitelisted emails in dev
     self.email.to = filter_whitelist_emails(self.email.to)
     self.email.cc = filter_whitelist_emails(self.email.cc)
     self.email.bcc = filter_whitelist_emails(self.email.bcc)
     # send with juntagrico mailer or custom mailer
     log.info(('Mail sent to ' + ', '.join(self.email.recipients()) + (', on whitelist' if settings.DEBUG else '')))
     mailer = import_string(Config.default_mailer())
     mailer.send(self.email)
Exemple #3
0
 def send(self):
     # only send to whitelisted emails in dev
     self.email.to = filter_whitelist_emails(self.email.to)
     self.email.cc = filter_whitelist_emails(self.email.cc)
     self.email.bcc = filter_whitelist_emails(self.email.bcc)
     # apply from filter
     if not re.match(Config.from_filter('filter_expression'),
                     self.email.from_email):
         reply_to = self.email.reply_to or [self.email.from_email]
         self.email.from_email = Config.from_filter('replacement_from')
         self.email.reply_to = reply_to
     # send with juntagrico mailer or custom mailer
     log.info(('Mail sent to ' + ', '.join(self.email.recipients()) +
               (', on whitelist' if settings.DEBUG else '')))
     mailer = import_string(Config.default_mailer())
     mailer.send(self.email)