Ejemplo n.º 1
0
def send_mass_mail(datatuple,
                   fail_silently=False,
                   auth_user=None,
                   auth_password=None,
                   encoding=None,
                   connection=None):
    """
    Given a datatuple of (subject, message, from_email, recipient_list), sends
    each message to each recipient list. Returns the number of e-mails sent.
    Also supports an optional encoding parameter to the datatuple. Individual
    items in the datatuple may have a fifth item which specifies the encoding
    of the particular email. Encodings in the datatuple have priority over
    the encoding passed to send_mass_mail.

    If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
    If auth_user and auth_password are set, they're used to log in.
    If auth_user is None, the EMAIL_HOST_USER setting is used.
    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.

    Note: The API for this method is frozen. New code wanting to extend the
    functionality should use the EmailMessage class directly.
    """
    connection = connection or get_connection(username=auth_user,
                                              password=auth_password,
                                              fail_silently=fail_silently)

    def _message(args):
        if isinstance(args, EmailMessage):
            return args
        if len(args) > 4:
            subject, body, sender, recipient, charset = args
        else:
            subject, body, sender, recipient = args
            charset = encoding or None
        message = EmailMessage(
            subject=subject,
            body=body,
            from_email=sender,
            to=recipient,
            connection=connection,
        )
        if charset:
            message.encoding = charset
        return message

    messages = [_message(d) for d in datatuple]

    for message in messages:
        mail_pre_send.send(sender=message, message=message)
    return_val = connection.send_messages(messages)
    for message in messages:
        mail_post_send.send(sender=message, message=message)
    return return_val
Ejemplo n.º 2
0
def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
                   auth_password=None, encoding=None, connection=None):
    """
    Given a datatuple of (subject, message, from_email, recipient_list), sends
    each message to each recipient list. Returns the number of e-mails sent.
    Also supports an optional encoding parameter to the datatuple. Individual
    items in the datatuple may have a fifth item which specifies the encoding
    of the particular email. Encodings in the datatuple have priority over
    the encoding passed to send_mass_mail.

    If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
    If auth_user and auth_password are set, they're used to log in.
    If auth_user is None, the EMAIL_HOST_USER setting is used.
    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.

    Note: The API for this method is frozen. New code wanting to extend the
    functionality should use the EmailMessage class directly.
    """
    connection = connection or get_connection(username=auth_user, password=auth_password,
                                              fail_silently=fail_silently)

    def _message(args):
        if isinstance(args, EmailMessage):
            return args
        if len(args) > 4:
            subject, body, sender, recipient, charset = args
        else:
            subject, body, sender, recipient = args
            charset = encoding or None
        message = EmailMessage(
            subject=subject,
            body=body,
            from_email=sender,
            to=recipient,
            connection=connection,
        )
        if charset:
            message.encoding = charset
        return message

    messages = [_message(d) for d in datatuple]

    for message in messages:
        mail_pre_send.send(sender=message, message=message)
    return_val = connection.send_messages(messages)
    for message in messages:
        mail_post_send.send(sender=message, message=message)
    return return_val
Ejemplo n.º 3
0
 def send(self, *args, **kwargs):
     mail_pre_send.send(sender=self, message=self)
     super(EmailMessage, self).send(*args, **kwargs)
     mail_post_send.send(sender=self, message=self)
Ejemplo n.º 4
0
 def send(self, *args, **kwargs):
     mail_pre_send.send(sender=self, message=self)
     super(EmailMessage, self).send(*args, **kwargs)
     mail_post_send.send(sender=self, message=self)