diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2010-10-07 23:36:02 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2010-10-07 23:36:02 +0000 |
| commit | 0aa438a3dff24a4e257a1190d2ba32893dfbc54d (patch) | |
| tree | 4de23b42a874fc10f462cc6ff6d2feca1d1ef53b /django | |
| parent | 2faa490aeb142345daf7d75a40b8c73e1099f6d8 (diff) | |
Fixed #7722 - added support for CC in EmailMessage.
Thanks to roberto.digirolamo for the report and initial patch, and
dougvanhorn and SmileyChris for further work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14000 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/mail/message.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 91a10a0a5c..a0cb09f7b8 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -105,7 +105,7 @@ class EmailMessage(object): encoding = None # None => use settings default def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, - connection=None, attachments=None, headers=None): + connection=None, attachments=None, headers=None, cc=None): """ Initialize a single email message (which can be sent to multiple recipients). @@ -119,6 +119,11 @@ class EmailMessage(object): self.to = list(to) else: self.to = [] + if cc: + assert not isinstance(cc, basestring), '"cc" argument must be a list or tuple' + self.cc = list(cc) + else: + self.cc = [] if bcc: assert not isinstance(bcc, basestring), '"bcc" argument must be a list or tuple' self.bcc = list(bcc) @@ -145,6 +150,8 @@ class EmailMessage(object): msg['Subject'] = self.subject msg['From'] = self.extra_headers.get('From', self.from_email) msg['To'] = ', '.join(self.to) + if self.cc: + msg['Cc'] = ', '.join(self.cc) # Email header names are case-insensitive (RFC 2045), so we have to # accommodate that when doing comparisons. @@ -162,9 +169,9 @@ class EmailMessage(object): def recipients(self): """ Returns a list of all recipients of the email (includes direct - addressees as well as Bcc entries). + addressees as well as Cc and Bcc entries). """ - return self.to + self.bcc + return self.to + self.cc + self.bcc def send(self, fail_silently=False): """Sends the email message.""" @@ -252,7 +259,8 @@ class EmailMultiAlternatives(EmailMessage): alternative_subtype = 'alternative' def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, - connection=None, attachments=None, headers=None, alternatives=None): + connection=None, attachments=None, headers=None, alternatives=None, + cc=None): """ Initialize a single email message (which can be sent to multiple recipients). @@ -261,7 +269,7 @@ class EmailMultiAlternatives(EmailMessage): bytestrings). The SafeMIMEText class will handle any necessary encoding conversions. """ - super(EmailMultiAlternatives, self).__init__(subject, body, from_email, to, bcc, connection, attachments, headers) + super(EmailMultiAlternatives, self).__init__(subject, body, from_email, to, bcc, connection, attachments, headers, cc) self.alternatives=alternatives or [] def attach_alternative(self, content, mimetype): |
