Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I send a Django email with a custom From header? #161

Closed
YPCrumble opened this issue Feb 6, 2018 · 2 comments
Closed

How do I send a Django email with a custom From header? #161

YPCrumble opened this issue Feb 6, 2018 · 2 comments
Labels

Comments

@YPCrumble
Copy link
Contributor

I'm attempting to set a different MAIL_FROM and From header in Django so that I can use a custom bounce domain. Django allows this by setting the bounce domain as the email's self.from_email attribute, and overriding the From header manually.

However, this yields the Sparkpost API error pasted below. I'm using Django Anymail 1.3 with python-sparkpost 1.3.5. Any suggestions would be tremendous!

Sending a message to test@example.com from mail@bounces.example.com
SparkPost API response 422: Unprocessable Entity
{
  "errors": [
    {
      "message": "Invalid header",
      "description": "Error while validating header From: 'From' header must be specified in content.from.name and content.from.email",
      "code": "3002"
    }
  ]
}
@YPCrumble
Copy link
Contributor Author

YPCrumble commented Feb 6, 2018

Update - it looks like the way this library constructs the from_email differs from how Django constructs the from_email attribute. Django first looks for From in its extra_headers attribute, while this library takes the from_email without allowing the override.

I'd be happy to submit a PR if that's helpful. I could also potentially understand suggesting that I add a custom return_path to Anymail's esp_extra dictionary, which I believe would adjust the currently undocumented return_path parameter on the transmissions.send method. Happy to add a PR to document return_path here if that's helpful instead: http://python-sparkpost.readthedocs.io/en/latest/api/transmissions.html?highlight=transactional#sparkpost.transmissions.Transmissions.send

@jgzamora
Copy link
Contributor

@YPCrumble awesome work digging up all the parts of this issue! I will document return_path for this lib and check if there are any other params that need documenting. It looks like your use case is currently possible, so I'm going close this issue. If you still still think we should update to better match how Django does this, please create another issue so we can discuss it in more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants