Last active
September 13, 2018 06:57
-
-
Save bubuzzz/d5f1e602112145f1eca980b4072e1bee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@receiver(post_save, sender=Feedback) | |
def post_save_feedback(sender, instance, *args, **kwargs): | |
params = {'user': instance.user, 'title': instance.title, 'content': instance.content} | |
subject = "There is a feedback from the app" | |
message_plain = render_to_string('%s/feedback/feedback.txt' % EMAIL_ROOT, params) | |
message_html = render_to_string('%s/feedback/feedback.html' % EMAIL_ROOT, params) | |
send_mail = SendMail(to=settings.ADMIN_CC_LIST, subject=subject, | |
message_plain=message_plain, message_html=message_html) | |
send_mail.start() | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from django.core.mail import send_mail | |
from django.core.exceptions import ImproperlyConfigured | |
import threading | |
class SendMail(threading.Thread): | |
def __init__(self, to, subject, message_plain, message_html=None): | |
super(SendMail, self).__init__() | |
from django.conf import settings | |
self.from_email = settings.EMAIL_HOST_USER | |
self.to = to | |
self.subject = subject | |
self.message_plain = message_plain | |
self.message_html = message_html | |
def run(self): | |
try: | |
html_message = self.message_html or self.message_plain | |
send_mail( | |
from_email=self.from_email, | |
recipient_list=self.to, | |
subject=self.subject, | |
message=self.message_plain, | |
html_message=html_message | |
) | |
print('successfully sent the mail') | |
except e: | |
print("Failed to send mail") | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment