Skip to content

6.0.2 fails to send to list of lists #778

Closed
@plowman

Description

@plowman

Issue Summary

Something I ran into while upgrading to 6.0.2 just now is that when sending a Mail object with a to_emails= parameter that is a list of [[email, name]], a confusing exception is thrown while if it's a list of [(email, name)], it succeeds.

This snippet fails

from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

email_list = [["[email protected]", "Benjamin Uno"],
              ["[email protected]", "Benjamin Dos"]]
mail = Mail(subject=subject,
            html_content=content,
            from_email=("[email protected]", "Website Team"),
            to_emails=email_list,
            )
sendgrid_client = SendGridAPIClient('abcd123')
sendgrid_client.send(mail)

The exception thrown is ValueError: Please use a To, Cc or Bcc object.

This snippet succeeds

email_list = [("[email protected]", "Benjamin Uno"),
              ("[email protected]", "Benjamin Dos")]

# (( Same code as above ))

Steps to Reproduce

  1. Run the initial snippet above

Expected

  • Option 1: accept a list of lists as well as a list of tuples. This seems doable but there may be ancient backwards incompatibility reasons why it's hard.
  • Option 2: fail immediately if you see a list of lists. Otherwise the error "Please use a To, Cc or Bcc object." is pretty confusing and took me a while to figure out why sendgrid was unhappy.

Technical details:

  • sendgrid-python Version: 6.0.2
  • Python Version: 3.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions