Ticket #6918: mail_patch.diff

File mail_patch.diff, 3.9 KB (added by Sung-jin Hong, 16 years ago)
  • django/core/mail.py

     
    195195    encoding = None     # None => use settings default
    196196
    197197    def __init__(self, subject='', body='', from_email=None, to=None, bcc=None,
    198             connection=None, attachments=None, headers=None):
     198            connection=None, attachments=None, headers=None, encoding=None):
    199199        """
    200200        Initialize a single email message (which can be sent to multiple
    201201        recipients).
     
    220220        self.attachments = attachments or []
    221221        self.extra_headers = headers or {}
    222222        self.connection = connection
     223        self.encoding = encoding
    223224
    224225    def get_connection(self, fail_silently=False):
    225226        if not self.connection:
     
    318319        self.attach(content=content, mimetype=mimetype)
    319320
    320321def send_mail(subject, message, from_email, recipient_list,
    321               fail_silently=False, auth_user=None, auth_password=None):
     322              fail_silently=False, auth_user=None, auth_password=None,
     323              encoding=None):
    322324    """
    323325    Easy wrapper for sending a single message to a recipient list. All members
    324326    of the recipient list will see the other recipients in the 'To' field.
    325327
    326328    If auth_user is None, the EMAIL_HOST_USER setting is used.
    327329    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
     330    If encoding is None, the DEFAULT_CHARSET setting is used.
    328331
    329332    Note: The API for this method is frozen. New code wanting to extend the
    330333    functionality should use the EmailMessage class directly.
     
    332335    connection = SMTPConnection(username=auth_user, password=auth_password,
    333336                                fail_silently=fail_silently)
    334337    return EmailMessage(subject, message, from_email, recipient_list,
    335                         connection=connection).send()
     338                        connection=connection, encoding=encoding).send()
    336339
    337340def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
    338                    auth_password=None):
     341                   auth_password=None, encoding=encoding):
    339342    """
    340343    Given a datatuple of (subject, message, from_email, recipient_list), sends
    341344    each message to each recipient list. Returns the number of e-mails sent.
     
    344347    If auth_user and auth_password are set, they're used to log in.
    345348    If auth_user is None, the EMAIL_HOST_USER setting is used.
    346349    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
     350    If encoding is None, the DEFAULT_CHARSET setting is used.
    347351
    348352    Note: The API for this method is frozen. New code wanting to extend the
    349353    functionality should use the EmailMessage class directly.
    350354    """
    351355    connection = SMTPConnection(username=auth_user, password=auth_password,
    352356                                fail_silently=fail_silently)
    353     messages = [EmailMessage(subject, message, sender, recipient)
     357    messages = [EmailMessage(subject, message, sender, recipient, encoding=encoding)
    354358                for subject, message, sender, recipient in datatuple]
    355359    return connection.send_messages(messages)
    356360
  • docs/email.txt

     
    245245      caller to ensure header names and values are in the correct format for
    246246      an e-mail message.
    247247
     248    * ``encoding``: The encoding of the email. Defaults to DEFAULT_CHARSET
     249      setting.
     250
    248251For example::
    249252
    250253    email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
    251254                ['to1@example.com', 'to2@example.com'], ['bcc@example.com'],
    252                 headers = {'Reply-To': 'another@example.com'})
     255                headers = {'Reply-To': 'another@example.com'},
     256                encoding = 'utf-8')
    253257
    254258The class has the following methods:
    255259
Back to Top