Closed chripede closed 8 years ago
This is a side-effect of the switch from pickling the email object to converting it to JSON for adding to the queue. We could provide hook for custom data that would be serialized and sent to the workers. Would something like the following work for you?
email.extra_data = {
'template_name': 'report-{}'.format(get_language()),
'template_content': {},
'global_merge_vars': {
'CLIENT': Client.objects.get(slug=client_slug).name,
},
}
You'd have to change how you get the data slightly, but it would be an easy thing to implement if it'd work.
It would solve my problem sure, but one would need to change the codebase if the email backend is changed, for instance in a test environment. Then it's no longer plug'n'play which would be a shame.
I don't think so. It should work the same in both cases. My solution just moves it to one specific extra attribute on the email object, which would be there in any backend that doesn't replace the object. But my backend would special case that attribute to make sure it's carried through since we're manually transmitting the data via JSON.
Wouldn't I need to change the parameters on EmailMessage back if I switched the backend from celery-email to djrill (mandrill)?
I don't know anything about djrill. I was assuming you could use any extra parameters you wanted, but if you need those specific params from your original question then yes, you're right. Will it only ever be those 3 extra params?
There's a lot of different params that you can use https://djrill.readthedocs.org/en/latest/usage/sending_mail/#mandrill-specific-options
Perhaps it's easier to make it configurable wether to pickle or convert to JSON
I've also needed this so I've put together some solution. Hope it helps. Made a pull request https://github.com/pmclanahan/django-celery-email/pull/31
Fixed in #31
I have my configuration set up like this
meaning that I use Mandrill to send mails.
In 1.0.4 I was able to set extra args on the EmailMessage object to use templates in Mandrill
All versions after 1.0.4 no longer sends these arguments all the way to Mandrill