Skip to content

is_multiple=True prevents use of dynamic template data #961

Open
@ghost

Description

Issue Summary

Hey all,

Using the mail helper with is_multiple=True causes the dynamic_template_data on the message not to propagate to the actual message. It seems that this data has to somehow be included individually in each personalization object, but I don't think I can set the Mail object's personalizations property manually, meaning there's no way to push the dynamic_template_data down into each of those objects.

If this is a bug, I would suggest automatically copying the dynamic_template_data to each personalization object when is_multiple is set to True.

Steps to Reproduce

  1. Create a simple Mail object, like so: Mail(from_email='[email protected]', to_emails=['one', 'two', ...], is_multiple=True
  2. Set the dynamic_template_data property.
  3. Set the template_id property.
  4. Send the email. Notice that all recipients receive it as they should, but that the dynamic template data does not come along for the ride.

Code Snippet

def send_notification_email(emails: list, dynamic_data: dict, file_content: str):
    message = Mail(
        from_email='[email protected]',
        to_emails=[To(email=email) for email in emails],
        is_multiple=True)
    message.dynamic_template_data = dynamic_data
    message.template_id = TemplateId('atemplateid')
    message.attachment = Attachment(FileContent(file_content), FileName('somename.someextension'))
    message.asm = Asm(GroupId(12345), GroupsToDisplay([12345]))
    sendgrid_client = SendGridAPIClient(os.environ['SENDGRID_API_KEY'])
    response = sendgrid_client.send(message)
    if response.status_code != 202:
        logging.info(response.status_code)
        raise Exception("Email send failed.")
    return response.body

Exception/Log

N/A, code executes "successfully".

Technical details:

  • sendgrid-python version: 6.4.8
  • python version: 3.8.6 64bit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions