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

Extra args on EmailMessage no longer working #25

Closed
chripede opened this issue Nov 5, 2015 · 8 comments
Closed

Extra args on EmailMessage no longer working #25

chripede opened this issue Nov 5, 2015 · 8 comments

Comments

@chripede
Copy link

chripede commented Nov 5, 2015

I have my configuration set up like this

EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
CELERY_EMAIL_BACKEND = "djrill.mail.backends.djrill.DjrillBackend"

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

email.template_name = 'report-{}'.format(get_language())
email.template_content = {}
email.global_merge_vars = {
    'CLIENT': Client.objects.get(slug=client_slug).name,
}

All versions after 1.0.4 no longer sends these arguments all the way to Mandrill

@pmclanahan
Copy link
Owner

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.

@chripede
Copy link
Author

chripede commented Nov 5, 2015

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.

@pmclanahan
Copy link
Owner

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.

@chripede
Copy link
Author

chripede commented Nov 6, 2015

Wouldn't I need to change the parameters on EmailMessage back if I switched the backend from celery-email to djrill (mandrill)?

@pmclanahan
Copy link
Owner

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?

@chripede
Copy link
Author

chripede commented Nov 6, 2015

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

@btx
Copy link
Contributor

btx commented Mar 10, 2016

I've also needed this so I've put together some solution. Hope it helps.
Made a pull request #31

@pmclanahan
Copy link
Owner

Fixed in #31

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

No branches or pull requests

3 participants