Recommendation: Django Post Office

868 views
Skip to first unread message

Maik Hoepfel

unread,
Dec 23, 2013, 8:26:07 AM12/23/13
to django...@googlegroups.com, django...@tangentlabs.co.uk
Hello,

SMTP is a verbose protocol that requires many interactions before an
email is sent; it can easily take 2+ seconds. This is unacceptable for
views in Oscar and we recommend using a non-default email backend.

From my experience with Bike Parts Market, I can recommend
https://github.com/ui/django-post_office. It gives quick access to sent
emails in the admin interface, and allows one to send emails
asynchronously. Personally, I trigger the management command with a cron
job that runs every minute. But if Celery is already running, one can
use that instead.

Post Office mainly uses email templates in the database. I've slightly
adapted it to allow sending email from file templates. I'm happy to
share that code if anyone is interested.

Regards,

Maik

asi...@gmail.com

unread,
Dec 23, 2013, 11:00:42 AM12/23/13
to django...@googlegroups.com, django...@tangentlabs.co.uk
Thanks for sharing.
I noticed that sending emails takes ~2 seconds and I'm planning to move to Celery to use worker for sending emails.

I'm interested, it would be nice if you could share it.
did you hook it up with the current method oscar is sending out emails?

thanks

Maik Hoepfel

unread,
Dec 23, 2013, 12:34:56 PM12/23/13
to django...@googlegroups.com
Hi,

you wire up Post Office by switching out the EMAIL_BACKEND. That will
work out of the box with Oscar, as it uses Django's default send_mail
function.

Templating of the email will still be done in the view (which could be
slow for HTML mails), but generally you'll see a big speedup.

Regards,

Maik

On 23/12/13 17:00, asi...@gmail.com wrote:
> Thanks for sharing.
> I noticed that sending emails takes ~2 seconds and I'm planning to move
> to Celery to use worker for sending emails.
>
> I'm interested, it would be nice if you could share it.
> did you hook it up with the current method oscar is sending out emails?
>
> thanks
>
> On Monday, December 23, 2013 3:26:07 PM UTC+2, Maik Hoepfel wrote:
>
> Hello,
>
> SMTP is a verbose protocol that requires many interactions before an
> email is sent; it can easily take 2+ seconds. This is unacceptable for
> views in Oscar and we recommend using a non-default email backend.
>
> From my experience with Bike Parts Market, I can recommend
> https://github.com/ui/django-post_office
> <https://github.com/ui/django-post_office>. It gives quick access to
> sent
> emails in the admin interface, and allows one to send emails
> asynchronously. Personally, I trigger the management command with a
> cron
> job that runs every minute. But if Celery is already running, one can
> use that instead.
>
> Post Office mainly uses email templates in the database. I've slightly
> adapted it to allow sending email from file templates. I'm happy to
> share that code if anyone is interested.
>
> Regards,
>
> Maik
>
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/e710cc67-5c1d-461f-9e3d-1c1edb2e26f1%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

asi...@gmail.com

unread,
Dec 23, 2013, 2:41:41 PM12/23/13
to django...@googlegroups.com
thanks, can you share your modified code?
do you use celery?

Maik Hoepfel

unread,
Dec 24, 2013, 5:19:00 AM12/24/13
to django...@googlegroups.com
As far as Post Office is concerned, just switch out the EMAIL_BACKEND as
documented.

I send non-Oscar emails from file-based templates. I pulled in code from
a few different projects to achieve that. I have one template per email,
and each has a subject, body, and html block. Template inheritance works
as expected, too. And it nicely wraps at 70-odd characters.

I'm afraid it's not well documented, but you can just read up on the
used projects: http://pastebin.com/7qPV4uPm

Cheers,

Maik

On 23/12/13 20:41, asi...@gmail.com wrote:
> thanks, can you share your modified code?
> do you use celery?
>
> On Monday, December 23, 2013 7:34:56 PM UTC+2, Maik Hoepfel wrote:
>
> Hi,
>
> you wire up Post Office by switching out the EMAIL_BACKEND. That will
> work out of the box with Oscar, as it uses Django's default send_mail
> function.
>
> Templating of the email will still be done in the view (which could be
> slow for HTML mails), but generally you'll see a big speedup.
>
> Regards,
>
> Maik
>
> <https://github.com/tangentlabs/django-oscar>
> > http://django-oscar.readthedocs.org/en/latest/
> <http://django-oscar.readthedocs.org/en/latest/>
> > https://twitter.com/django_oscar <https://twitter.com/django_oscar>
> > ---
> > You received this message because you are subscribed to the Google
> > Groups "django-oscar" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to django-oscar...@googlegroups.com <javascript:>.
> <http://groups.google.com/group/django-oscar>.
> <https://groups.google.com/d/msgid/django-oscar/e710cc67-5c1d-461f-9e3d-1c1edb2e26f1%40googlegroups.com>.
>
> > For more options, visit https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/1932deaa-4a08-440a-8d32-2405b305de82%40googlegroups.com.

asi...@gmail.com

unread,
Jan 6, 2014, 10:33:47 AM1/6/14
to django...@googlegroups.com
Maik, Oscar uses Django's default send_mail function, I don't need to change it to django-post-office send_mail function?
I'm asking since you did not mention anything about such change.

10x

asi...@gmail.com

unread,
Jan 7, 2014, 3:55:08 AM1/7/14
to django...@googlegroups.com
I just answered my own question by going over django-post-office source code.
Maik, have you even though about creating a custom EmailBackend to gather as many Oscar emails in X minutes and to use
send_many function of django-post-office?

This would save lots of DB access.

10x

Aaron Kim

unread,
Jan 17, 2017, 1:16:48 AM1/17/17
to django-oscar, maik.h...@tangentsnowball.com
Please help a newbie here. I still don't get it. Don't you have to override customer app to use Post Office instead of django.core.mail to hook up? I can't find where and how you set host configuration for this backend as well. 
Reply all
Reply to author
Forward
0 new messages