Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set correct variables. #3

Merged
merged 4 commits into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions django_mailjet/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from base64 import b64encode
from email.mime.base import MIMEBase
from email.utils import parseaddr
from mailjet import Client
from mailjet_rest import Client


from django.conf import settings
Expand Down Expand Up @@ -42,7 +42,7 @@ def _parse_recipients(self, message, recipients):
recipient_vars = getattr(message, 'recipient_vars', {})

for addr in recipients:
to_email, to_name = parseaddr(sanitize_address(addr, message.encoding))
to_name, to_email = parseaddr(sanitize_address(addr, message.encoding))
rcpt = {'Email': to_email, 'Name': to_name}

if recipient_vars.get(addr):
Expand Down Expand Up @@ -109,16 +109,15 @@ def _build_standart_message_dict(self, message):
msg_dict['FromEmail'] = from_email
msg_dict['FromName'] = from_name

# msg_dict['To'] = message.to
msg_dict['Recipients'] = self._parse_recipients(message, message.to)
msg_dict['To'] = ', '.join([sanitize_address(addr, message.encoding) for addr in message.to])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think changing Recipients to To is a good idea...

From Mailjet docs...

Important: Recipients and To have a different behaviors. The recipients listed in To
will recieve a common message showing every other recipients and carbon copies
recipients. The recipients listed in Recipients will each recieve an seperate message
without showing all the other recipients. 


if hasattr(message, 'cc'):
msg_dict['Cc'] = message.cc
if message.cc:
msg_dict['Cc'] = ', '.join([sanitize_address(addr, message.encoding) for addr in message.cc])

if hasattr(message, 'bcc'):
msg_dict['bcc'] = message.bcc
if message.bcc:
msg_dict['Bcc'] = ', '.join([sanitize_address(addr, message.encoding) for addr in message.bcc])

if hasattr(message, 'reply_to'):
if message.reply_to:
reply_to = [sanitize_address(addr, message.encoding) for addr in message.reply_to]
msg_dict['Headers'] = {'Reply-To': ', '.join(reply_to)}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def read(*parts):
filename = path.join(path.dirname(__file__), *parts)
with open(filename, encoding='utf-8') as fp:
with open(filename) as fp:
return fp.read()


Expand Down