anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.67k stars 129 forks source link

Handlebars variables not substitued in mandrill templates #331

Closed pcyrille closed 1 year ago

pcyrille commented 1 year ago

Hello everyone :)

I recently upgraded django-anymail to version 10.0 and had an issue with emails sent via mandrill handlebars templates.

I don’t have any error message but, even though the variables are sent as a dictionnary via the merge_global_data setting, the variables are not substituted in the template and the latter is sent with all handlebars syntax visible.

For now, I solved my problem by downgrading the version back to 9.1, without changing anything in the code.

If needed, here is a sample of the python code I use to send emails, which works in version 9.1 but breaks in version 10.0 :

message = AnymailMessage(to=[serialized_user["email"]])
message.template_id = template
message.merge_language = "handlebars"
message.track_opens = True
message.track_clicks = True
message.merge_global_data = merge_data # emails variables dictionnary
message.from_name = sender_name
message.from_email = sender_email

if "MAIL_SUBJECT" in merge_data:
    message.subject = merge_data.get("MAIL_SUBJECT")

message.send()

Has something in mandrill ESP support changed ? Tell me if you need more information.

Have a nice day :)

medmunds commented 1 year ago

Has something in mandrill ESP support changed ?

Anymail keeps a detailed changelog. See https://anymail.dev/en/stable/changelog/#v10-0. Some relevant info is right after the boldfaced word "Mandrill".

It seems like your code might have been written for Anymail's predecessor project Djrill? If so, it would be a very good idea to review the entire Migrating from Djrill section in Anymail's docs. You might also want to enable Python deprecation warnings—while you are still running an older Anymail release, this should tell you exactly what needs to be changed.

(Also, btw, neither Anymail nor Djrill have ever supported setting from_name like you show—that's just getting ignored. You can use Python's email.utils.formataddr to include a display name in your from_email.)