Giter Club home page Giter Club logo

Comments (9)

medmunds avatar medmunds commented on May 24, 2024

Just to double-check: you've switched your code to use template_id rather than template_name (and merge_data rather than merge_vars), right?

(If you're migrating from Djrill, some of the Mandrill-specific attributes have been renamed in Anymail. The old Djrill attrs are still supported -- with deprecation warnings -- in Anymail's Mandrill backend, but not in the other ESP backends. Full list and a grep to help find them in the doc link above.)

If that's not the problem, it would be helpful to see the specific code that isn't working.

from django-anymail.

ojwoodford avatar ojwoodford commented on May 24, 2024

I didn't see any warnings in my console, but I'm setting the:

  • template_name
  • global_merge_vars

attributes of my EmailMessage object before sending. I'm using Django 1.8.

It's difficult to know what code isn't working, because there are no errors.

If I change template_name to template_id and also global_merge_vars to merge_global_data I do get an error:

Exception Type: AnymailAPIError
Exception Value:    
Call to https://api.sparkpost.com/api/v1/transmissions returned 422, errors:
        invalid combination of fields: Both content object and template_id are specified

Sending a message to xxx from xxx
ESP API response 422:
{
  "errors": [
    {
      "message": "invalid combination of fields", 
      "code": "1301", 
      "description": "Both content object and template_id are specified"
    }
  ]
}

Mandrill works fine with those changes.

from django-anymail.

medmunds avatar medmunds commented on May 24, 2024

OK, there are two problems here:

  1. Anymail has a bug with SparkPost stored templates leading to the 422 response you've listed above. I'm looking into that right now.
  2. Your code is using the old Djrill attribute names. You'll need to update them before switching from Mandrill to another Anymail ESP backend (like SparkPost). Please read through Anymail's docs on migrating from Djrill and change your code as needed.

To assist with migrating from Djrill to Anymail, Anymail issues DeprecationWarnings when you are using Anymail's Mandrill backend and use the Djrill names. (The new Anymail backends like SparkPost don't even bother looking for the old Djrill names. It's best to work through the migration docs before switching ESPs.)

Those warnings should show up in your dev server logs (and Django test output, if you have tests on email sending). If you'd like to change the warnings to errors to make them more visible see this StackOverflow answer.

Or you can run this git grep command at the root of your project to find all instances of old Djrill names that need updating (from the migration docs):

git grep -w \
  -e 'async' -e 'auto_html' -e 'auto_text' -e 'from_name' -e 'global_merge_vars' \
  -e 'google_analytics_campaign' -e 'google_analytics_domains' -e 'important' \
  -e 'inline_css' -e 'ip_pool' -e 'merge_language' -e 'merge_vars' \
  -e 'preserve_recipients' -e 'recipient_metadata' -e 'return_path_domain' \
  -e 'signing_domain' -e 'subaccount' -e 'template_content' -e 'template_name' \
  -e 'tracking_domain' -e 'url_strip_qs' -e 'use_template_from' -e 'use_template_subject' \
  -e 'view_content_link'

from django-anymail.

ojwoodford avatar ojwoodford commented on May 24, 2024

This stackoverflow question is also relevant. That's where I (and possibly anymail) am going wrong.

from django-anymail.

medmunds avatar medmunds commented on May 24, 2024

Ah - thanks -- that's exactly the problem. I'll have to figure out how to convince python-sparkpost not to put anything else in the content payload.

from django-anymail.

medmunds avatar medmunds commented on May 24, 2024

Pushing a fix momentarily. Until then, workaround is to explicitly specify subject=None, body=None on your EmailMessage. (SparkPost is balking on the default empty strings for these fields.)

from django-anymail.

ojwoodford avatar ojwoodford commented on May 24, 2024

Many thanks @medmunds. The workaround has done the trick. Any chance of a new version number so that I can pip install on a server? No worries if not.

from django-anymail.

medmunds avatar medmunds commented on May 24, 2024

No problem -- thanks for catching it and identifying the cause.

New version will be 0.4.2. Just waiting for Travis-CI to approve, and then will push to PyPI.

from django-anymail.

medmunds avatar medmunds commented on May 24, 2024

Release 0.4.2 is live

from django-anymail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.