diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index ce8bb2f0c..db2399310 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -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: diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index dff3de5b2..202d3948b 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -14,7 +14,7 @@ ClickTracking, Content, DynamicTemplateData, Email, From, Mail, Personalization, - Subject, Substitution, To, TrackingSettings + Subject, Substitution, To, Cc, Bcc, TrackingSettings ) @@ -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( - 'and easy to do anywhere, even with Python')) - 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( + 'and easy to do anywhere, even with Python')) 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( - 'and easy to do anywhere, even with Python')) - 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( + 'and easy to do anywhere, even with Python')) 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( - 'and easy to do anywhere, even with Python')) - 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( + 'and easy to do anywhere, even with Python')) 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( - 'and easy to do anywhere, even with Python')) - 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( + 'and easy to do anywhere, even with Python')) + + 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( + 'and easy to do anywhere, even with Python')) def test_dynamic_template_data(self): self.maxDiff = None