Skip to content

Inconsistent format of email from header “name <email>” #277

@andriisoldatenko

Description

@andriisoldatenko

Issue Summary

Current implementation restrict use default email_from behavior. For more info please see https://tools.ietf.org/html/rfc2822#section-3.4

Steps to Reproduce

  1. When user try to create Email instance from https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py#L173-L179. You must specify
    from_email and from_name as seperate parametrs
    def get(self):
        email = {}
        if self.name != None:
            email["name"] = self.name
        if self.email != None:
            email["email"] = self.email
        return email

from_email = Email("[email protected]", "Example Name")

As a result client should split from_email:

try:
    import rfc822
except ImportError:
    import email.utils as rfc822


from_name, from_email = rfc822.parseaddr(email.from_email)
# Python sendgrid client should improve
# sendgrid/helpers/mail/mail.py:164
if not from_name:
    from_name = None
Mail(from_email, from_name)

Proposal to how to improve this bahaviour.
Because if user now create Email from:

from_email = Email("Andrii Soldatenko <[email protected]>")

Actual result:
image

Technical details:

  • sendgrid-python Version: master
  • Python Version: all

References:

NOTE:
In sengrid-python==1.4 this feature is working

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