Package: django-simple-mail
django-simple-mailSimple customizable email template built for DjangoChangelog2.3.5 Fixugettext_lazydeprecation for django 42.3.4 Add default value forSIMPLE_MAIL_FILE_STORAGEsetting2.3.3 Add storage settings for ImageSpecField2.3.2 AddSIMPLE_MAIL_FILE_STORAGEsetting2.3.1 Fix six import issue2.3.0 Drop Python 2 support and add Django 3.0 compatibility2.2.6 Disable autoescape for email subject2.2.5 Remove unused arguments fromsend_mass_mailmethod ofBaseSimpleMail2.2.4 Addsend_mass_mailmethod toBaseSimpleMail2.2.3 Remove actions from admin (we do not have delete permissions)2.2.2 Add Django 1.9 and Python 2 compatibility2.2.1 Remove cssutils Warning from logsIn the 2.2.* version the following fieldsfrom_email,from_nameandbase_urlwhere removed. Those parameters should
be defined in code rather than from the admin.The 2.* versions have breaking changes from the 1.* and are not
backward compatible.Template previewThe base template was built withMailchimpeditor :Email PreviewRequirementsThis Django app works with :Python (>=2.7)Django (>=1.9) (Need to be tested for previous versions)TodoWrite testsvalidate compatibility with previous versions of Django and PythonSet a demo app on pythonanywhereInstallationInstall usingpip:pip install django_simple_mailAddsimple_mailto your INSTALLED_APPS settings.INSTALLED_APPS=(...'simple_mail',...)Then run :python manage.py migrateQuoting Django’s documentation :Mail is sent using the SMTP host and port specified in theEMAIL_HOSTandEMAIL_PORTsettings. TheEMAIL_HOST_USERandEMAIL_HOST_PASSWORDsettings, if set, are used to
authenticate to the SMTP server, and theEMAIL_USE_TLSandEMAIL_USE_SSLsettings control whether a secure connection is
used.So you need to set the followingEMAIL_HOST = ''
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = True
EMAIL_USE_SSL = FalseIntegrationsCKEDITOR for a WYSIWYG edition of contentsSimple Mail easily integrates withdjango-ckeditorto have a wysiwyg
edition of content. To use it :pip installdjango-ckeditorThen addckeditorto your INSTALLED_APPS settings.INSTALLED_APPS=(...'ckeditor',...)And set the following in your settings :SIMPLE_MAIL_USE_CKEDITOR = TrueModelTranslation to translate emailsSimple Mail easily integrates withdjango-modeltranslationto get
the content of your emails available in multiple languages.pip installdjango-modeltranslationThen addmodeltranslationto your INSTALLED_APPS settings.INSTALLED_APPS=(...'modeltranslation',...)And set the following in your settings :SIMPLE_MAIL_USE_MODELTRANSALTION = TrueAnd run :python manage.py sync_translation_fieldsCreate, register and send mailsRegister MailCreate amails.pyfile in your app and define your mail.Theemail_keyattribute must not exceed 100 characters.fromsimple_mail.mailerimportBaseSimpleMail,simple_mailerclassWelcomeMail(BaseSimpleMail):email_key='welcome'simple_mailer.register(WelcomeMail)Then run./manage.py register_mailsto create those mail into the
database.The mail with keywelcomewill he be available for edition in your
django admin.Send an emailYou can the send theWelcomeMailthe following way :welcome_mail=WelcomeMail()welcome_mail.send(to,from_email=None,bcc=[],connection=None,attachments=[],headers={},cc=[],reply_to=[],fail_silently=False)Passing variables to emailYou can pass variable to email with thecontextattribute :fromsimple_mail.mailerimportBaseSimpleMail,simple_mailerclassWelcomeMail(BaseSimpleMail):email_key='welcome'context={'title':'My email title','user':'the user'}simple_mailer.register(WelcomeMail)Or you can create aset_contextmethod:fromsimple_mail.mailerimportBaseSimpleMail,simple_mailerclassWelcomeMail(BaseSimpleMail):email_key='welcome'defset_context(self,user_id,welcome_link):user=User.objects.get(id=user_id)self.context={'user':user,'welcome_link':welcome_link}simple_mailer.register(WelcomeMail)You will then need to call theset_contextbefore sending an email:welcome_mail=WelcomeMail()welcome_mail.set_context(user_id,welcome_link)welcome_mail.send(to,from_email=None,bcc=[],connection=None,attachments=[],headers={},cc=[],reply_to=[],fail_silently=False)Email preview and test emailFrom the admin you can preview an email and send a test email.Both methods use yourcontextattribute to render the email.If you use theset_contextmethod, you might need to create aset_test_contextmethod.This method should not take any argument :fromsimple_mail.mailerimportBaseSimpleMail,simple_mailerclassWelcomeMail(BaseSimpleMail):email_key='welcome'defset_context(self,user_id,welcome_link):user=User.objects.get(id=user_id)self.context={'user':user,'welcome_link':welcome_link}defset_test_context(self):user_id=User.objects.order_by('?').first().idself.set_context(user_id,'http://my-webiste.com/my-path')simple_mailer.register(WelcomeMail)This method impact the fields displayed in theContextsection of
the admin.SettingsHere are all the settings you can use, with their default value :# enable django-modeltranslation integration
SIMPLE_MAIL_USE_MODELTRANSALTION = False
# enable django-ckeditor integration
SIMPLE_MAIL_USE_CKEDITOR = False
# set default email template
SIMPLE_MAIL_DEFAULT_TEMPLATE = 'simple_mail/default.html'
# enable/disable cssutils warning logs
SIMPLE_MAIL_LOG_CSS_WARNING = False
# storage for logo and banner
SIMPLE_MAIL_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'Mail configuration & editionCustomize your base content and template colorsYou change the look and feel or your template directly from the django
admin : TheFooterfield can use template tags and variables.Admin mail configurationEdit the content of each of your mail :You can edit the content of each of your mail. TheContent,Subject,button labelandbutton linkfields can use
template tags and variables.Admin mail editionCustom templateYou can define your own email template :By setting atemplateattribute from youBaseSimpleMailsubclass :fromsimple_mail.mailerimportBaseSimpleMail,simple_mailerclassWelcomeMail(BaseSimpleMail):email_key='welcome'template='my_app/my_email_template.html'simple_mailer.register(WelcomeMail)Or by settingSIMPLE_MAIL_DEFAULT_TEMPLATEin your settings :SIMPLE_MAIL_DEFAULT_TEMPLATE='my_app/my_email_template.html'SupportIf you are having issues, please let us know or submit a pull request.LicenseThe project is licensed under the MIT License.