Skip to content
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
4 changes: 2 additions & 2 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ def add_to(
email = To(email, None)
elif isinstance(email, tuple):
email = To(email[0], email[1])
elif not isinstance(email, To):
elif not isinstance(email, Email):
raise ValueError(
'Please use a tuple, To, or a str for a to_email list.'
'Please use a To/Cc/Bcc, tuple, or a str for a to_email list.'
)
self._set_emails(email, global_substitutions, is_multiple, p)
else:
Expand Down
96 changes: 51 additions & 45 deletions test/test_mail_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ClickTracking, Content,
DynamicTemplateData, Email, From,
Mail, Personalization,
Subject, Substitution, To, TrackingSettings
Subject, Substitution, To, Cc, Bcc, TrackingSettings
)


Expand Down Expand Up @@ -310,68 +310,74 @@ def test_error_is_not_raised_on_to_emails_set_to_list_of_tuples(self):
('test+to1@example.com', 'Example To Name 1')
]

try:
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))
except:
self.fail('Mail() raised an error on list of tuples')
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))

def test_error_is_not_raised_on_to_emails_set_to_list_of_strs(self):
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent)
self.maxDiff = None
to_emails = ['test+to0@example.com', 'test+to1@example.com']

try:
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))
except:
self.fail('Mail() raised an error on list of strings')
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))

def test_error_is_not_raised_on_to_emails_set_to_a_str(self):
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent)
self.maxDiff = None
to_emails = 'test+to0@example.com'

try:
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))
except:
self.fail('Mail() raised an error on a string')
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))

def test_error_is_not_raised_on_to_emails_set_to_a_tuple(self):
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent)
self.maxDiff = None
to_emails = ('test+to0@example.com', 'Example To Name 0')

try:
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))
except:
self.fail('Mail() raised an error on a tuple of strings')
Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))

def test_error_is_not_raised_on_to_emails_includes_bcc_cc(self):
from sendgrid.helpers.mail import (PlainTextContent, HtmlContent)
self.maxDiff = None
to_emails = [
To('test+to0@example.com', 'Example To Name 0'),
Bcc('test+bcc@example.com', 'Example Bcc Name 1'),
Cc('test+cc@example.com', 'Example Cc Name 2')
]

Mail(
from_email=From('test+from@example.com', 'Example From Name'),
to_emails=to_emails,
subject=Subject('Sending with SendGrid is Fun'),
plain_text_content=PlainTextContent(
'and easy to do anywhere, even with Python'),
html_content=HtmlContent(
'<strong>and easy to do anywhere, even with Python</strong>'))

def test_dynamic_template_data(self):
self.maxDiff = None
Expand Down