Пример #1
0
    def send_email(email):
        """Sends an email

        :param email: Email object
        :type emails: Email
        """
        if not isinstance(email, Email):
            raise TypeError(u'email is not instance of Email')

        with mail.connect() as conn:
            email.sent_at = datetime.utcnow()
            conn.send(email.msg)
Пример #2
0
    def send_emails(emails):
        """Sends emails

        :param emails: List of emails
        :type emails: List
        """
        with mail.connect() as conn:
            for email in emails:
                try:
                    email.sent_at = datetime.utcnow()
                    conn.send(email.msg)
                except Exception as e:
                    app.logger.exception(u'Failed to send email {0}: Exception: {0}'
                                         .format(email, e))

        app.logger.info(u'Sent {0} email updates. Emails: {1}'.format(len(emails), emails))
Пример #3
0
def when_user_confirmed(sender, user):
    """Called when 'user-confirmed' signal sent.
    Sends an email to admins to celebrate.

    sender -- the sender of the signal
    user -- a new User
    """
    app.logger.info(u'User {0} confirmed'.format(user))

    msg = Message(
        sender=(app.config['PROJECT_NAME'], app.config['MAIL_DEFAULT_SENDER']),
        recipients=app.config['ADMIN_EMAILS'],
        subject='New {0} User Confirmed'.format(app.config['PROJECT_NAME']),
        body=u'User {0} confirmed.'.format(user))

    with mail.connect() as conn:
        conn.send(msg)