Alex Rivera | Logout

EmailBackend for sending email through multiple SMTP in Django

Asked 2012-11-27T18:18:24.863
37

Getting Django to send an email is nicely explained here using standard settings as shown below.

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = "mail.mysmtpserver.somewhere"
#EMAIL_PORT
EMAIL_HOST_USER = "my@login"
EMAIL_HOST_PASSWORD = "mypassword"
#EMAIL_USE_TLS = True

Then using django.core.mail.EmailMessage to send it of.

How ever, what if you are running multiple sites and need each of these to send email through their own SMTP server (or just different login in the same SMTP server)?

Searching for a EmailBackend like this or a way to do it with the current backend did not produce any satisfactory results.

Edit
Report

1 Answer

0

use a different configuration for each site.

one way is to have, in addition to your settings.py, a settings_SITENAME.py for each site. these files will have the custom mail server settings. each site will have settings_local.py be a symlink to it's own custom settings file

then put this stanza at the bottom of settings.py:

try:                                                                                                                                                                            
    from settings_local import *                                                                                                                                                
except ImportError:                                                                                                                                                             
    pass  

now you have per-site custom settings

answered 2012-11-27T19:18:58.913

Your Answer