Django emailbackend that using OAuth Gmail API or SMTP server.
Project description
django-oauth-emailbackend
Django emailbackend that using OAuth Gmail API or SMTP server.
Installation
First, install the python package.
pip install django-oauth-emailbackend
Then, add the following to the settings.py
of your project:
INSTALLED_APPS = [
...
'django.contrib.sites',
'oauth_emailbackend',
...
]
#----- django-oauth-emailbackend settings -----#
# EMAIL_BACKEND를 OAuthEmailBackend 설정
# Celery를 이용하여 발송하는 경우 CELERY_BROKER_URL 값을 설정하여야 합니다.
EMAIL_BACKEND = 'oauth_emailbackend.backends.OAuthEmailBackend'
# 발송내역을 저장할 DATABASE_NAME
OAUTH_EMAILCLIENT_DBNAME = 'default'
# OAuth 목록
OAUTH_EMAILBACKEND_PROVIDERS = (
'oauth_emailbackend.providers.gmail',
)
# 콜백 도메인을 현재 사이트 도메인과 다르게 지정하려면 설정. 예) https://domain.to
OAUTH_EMAILBACKEND_CALLBACK_HOST = None
OAUTH_EMAILBACKEND_USE_CELERY = True
OAUTH_EMAILBACKEND_CELERY_MAX_RETRY = 3 # default=3
# OS SMTP server name
OAUTH_EMAILBACKEND_MTA = 'postfix' # [None|postfix]
#----- celery settings -----#
# Celery를 이용하여 발송할 경우 CELERY_BROKER_URL 세팅
CELERY_BROKER_URL = "<broker url for celery>"
#
# * Test run celery in localhost
# celery -A config worker -l info -E
Additionally, add this to your project urls.py:
urlpatterns = [
...
# Add OAuth Emailbackend urls
path('oauth_emailbackend/', include('oauth_emailbackend.urls')),
...
]
Post-Installation
In your Django root execute the command below to create your database tables:
python manage.py migrate
Register API client on the admin page
Visit https://<host>/admin/oauth_emailbackend/oauthapi/
and
add OAuth API and Email Client app sequentially.
Test
from django.core.mail import send_mail
send_mail("Subject here",
"Here is the message.",
"<sender-email-address>",
["<recipient-email-address>"],
fail_silently=False)
Providers
Gmail
https://developers.google.com/gmail/api/guides
https://console.cloud.google.com/
API 개설- 사용자 인증 정보 에서
OAuth 2.0 클라이언트 ID
생성 - OAuth 동의 화면 구성
- 승인된 리디렉션 URI에는
https://<host>/oauth_emailbackend/oauth2callback/gmail
을 입력
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_oauth_emailbackend-0.1.6.tar.gz
.
File metadata
- Download URL: django_oauth_emailbackend-0.1.6.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24e739bbf2a6661afb41d870a4164eab94d4b6d0ebeb3415eaa55807aa4bbcff |
|
MD5 | ae710e128df8ac7b3bed53cd562f3f60 |
|
BLAKE2b-256 | 7eb035b6d3b8eed895e1ee1126d829aabb5a0230f737bc266e185e87c69b407d |
File details
Details for the file django_oauth_emailbackend-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: django_oauth_emailbackend-0.1.6-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2548f643170b824f251221f53bad97178752add1ed7e4483ed162b9f61dfaff1 |
|
MD5 | 11b0c234a71f936c7a65df5b395747e5 |
|
BLAKE2b-256 | 4a93870baaa94288b9601523d533811eba334f507dca32d6da185baf7ae3d5ac |