|
|
@ -1,6 +1,7 @@ |
|
|
from _socket import gaierror |
|
|
from _socket import gaierror |
|
|
from smtplib import SMTPException |
|
|
from smtplib import SMTPException |
|
|
from django.core.mail import send_mail |
|
|
|
|
|
|
|
|
from django.core.mail import EmailMultiAlternatives |
|
|
|
|
|
from django.utils.html import strip_tags |
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
from chatbot.models import ChatException |
|
|
from chatbot.models import ChatException |
|
|
@ -10,12 +11,16 @@ def send_notify(msg_text, account, tag='none'): |
|
|
try: |
|
|
try: |
|
|
# MessageQueue.objects.push(msg=msg_text, user=account, tag=tag) |
|
|
# MessageQueue.objects.push(msg=msg_text, user=account, tag=tag) |
|
|
target_email = account.email |
|
|
target_email = account.email |
|
|
send_mail( |
|
|
|
|
|
|
|
|
text_content = strip_tags(msg_text) |
|
|
|
|
|
|
|
|
|
|
|
msg = EmailMultiAlternatives( |
|
|
subject=getattr(settings, 'COMPANY_NAME', 'Djing notify'), |
|
|
subject=getattr(settings, 'COMPANY_NAME', 'Djing notify'), |
|
|
message=msg_text, |
|
|
|
|
|
|
|
|
body=text_content, |
|
|
from_email=getattr(settings, 'DEFAULT_FROM_EMAIL'), |
|
|
from_email=getattr(settings, 'DEFAULT_FROM_EMAIL'), |
|
|
recipient_list=(target_email,) |
|
|
|
|
|
|
|
|
to=(target_email,) |
|
|
) |
|
|
) |
|
|
|
|
|
msg.attach_alternative(msg_text, 'text/html') |
|
|
|
|
|
msg.send() |
|
|
except SMTPException as e: |
|
|
except SMTPException as e: |
|
|
raise ChatException('SMTPException: %s' % e) |
|
|
raise ChatException('SMTPException: %s' % e) |
|
|
except gaierror as e: |
|
|
except gaierror as e: |
|
|
|