Add email sending task

This commit is contained in:
R. Miles McCain 2020-05-09 12:35:50 -04:00
parent 6978bbd03e
commit 4569744726
No known key found for this signature in database
GPG Key ID: 24F9B6A2588C5408
3 changed files with 26 additions and 1 deletions

View File

@ -24,6 +24,7 @@ redis = "*"
django-redis-cache = "*"
pycountry = "*"
ipaddress = "*"
html2text = "*"
[pipenv]
allow_prereleases = true

10
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "75fe7f0efbc05d6bc32c5ccaa08d3d619bf925682ca5eaffa728e74d0e8e5f66"
"sha256": "e66668cad32f92f11324d92caa0e3e83afcb3cafe471f3ba1f178fc090dd7b6b"
},
"pipfile-spec": 6,
"requires": {},
@ -118,6 +118,14 @@
"index": "pypi",
"version": "==20.0.4"
},
"html2text": {
"hashes": [
"sha256:c7c629882da0cf377d66f073329ccf34a12ed2adf0169b9285ae4e63ef54c82b",
"sha256:e296318e16b059ddb97f7a8a1d6a5c1d7af4544049a01e261731d2d5cc277bbb"
],
"index": "pypi",
"version": "==2020.1.16"
},
"idna": {
"hashes": [
"sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb",

16
shynet/dashboard/tasks.py Normal file
View File

@ -0,0 +1,16 @@
from celery import shared_task
from django.core import mail
from django.conf import settings
import html2text
@shared_task
def send_email(to: [str], subject: str, content: str, from_email: str = None):
text_content = html2text.html2text(content)
mail.send_mail(
subject,
text_content,
from_email or settings.DEFAULT_FROM_EMAIL,
to,
html_message=content,
)