2. Installation¶
pip install django-sendmail
To enable JSON editing functionality for Newsletter in the admin interface, install with django-jsoneditor
optional dependency.
pip install django-sendmail[jsoneditor]
Add sendmail and ckeditor to your installed apps in settings.py:
INSTALLED_APPS = [
# other apps,
'ckeditor',
'ckeditor_uploader',
'sendmail',
'jsoneditor' # if installed
]
To your settings.py also add email server configurations:
EMAIL_HOST = '<your-smtp-host.com>'
EMAIL_PORT = <SMTP port>
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'default@email.com'
To your list of template engines (TEMPLATES) settings add a special template backend:
TEMPLATES = [
{
'BACKEND': 'sendmail.template.backends.sendmail.SendMailTemplates',
'APP_DIRS': True,
'DIRS': [BASE_DIR / 'templates', ...],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.template.context_processors.request',
]
}
},
...
Add CKEDITOR_UPLOAD_PATH. This path will be used to store ckeditor uploaded images inside MEDIA_ROOT:
CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads'
To your main urls.py add ckeditor_uploader urls.
urlpatterns = [
...
path('ckeditor/', include('ckeditor_uploader.urls')),
]
Add STATIC_URL and STATIC_ROOT
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
Add MEDIA_URL and MEDIA_ROOT
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'workdir' / 'media'
Run migrate:
python manage.py migrate
Run collectstatic:
python manage.py collectstatic
Set sendmail.EmailBackend as your EMAIL_BACKEND in django’s settings.py:
EMAIL_BACKEND = 'sendmail.EmailBackend'