2017-10-01 19:54:34 +00:00
|
|
|
import logging
|
|
|
|
|
2017-04-18 06:34:23 +00:00
|
|
|
from celery import shared_task
|
2017-10-01 19:54:34 +00:00
|
|
|
from envelopes import Envelope
|
|
|
|
|
|
|
|
from options.options import SysOptions
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2017-04-18 17:37:10 +00:00
|
|
|
|
2017-10-01 19:54:34 +00:00
|
|
|
def send_email(from_name, to_email, to_name, subject, content):
|
|
|
|
smtp = SysOptions.smtp_config
|
|
|
|
if not smtp:
|
|
|
|
return
|
|
|
|
envlope = Envelope(from_addr=(smtp["email"], from_name),
|
|
|
|
to_addr=(to_email, to_name),
|
|
|
|
subject=subject,
|
|
|
|
html_body=content)
|
|
|
|
try:
|
|
|
|
envlope.send(smtp["server"],
|
|
|
|
login=smtp["email"],
|
|
|
|
password=smtp["password"],
|
|
|
|
port=smtp["port"],
|
|
|
|
tls=smtp["tls"])
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
|
|
logger.exception(e)
|
|
|
|
return False
|
2017-04-18 06:34:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2017-04-18 18:03:48 +00:00
|
|
|
def send_email_async(from_name, to_email, to_name, subject, content):
|
2017-04-18 06:34:23 +00:00
|
|
|
send_email(from_name, to_email, to_name, subject, content)
|