Last active
May 14, 2021 20:01
-
-
Save rturowicz/5227981 to your computer and use it in GitHub Desktop.
django - send email
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
from django.http import HttpResponse | |
from django.core.mail import send_mail | |
from django.template import Context | |
from django.template import loader | |
from socket import error as SocketError | |
subject = 'subject' | |
c = Context({ | |
'from': '[email protected]', | |
'tmp': 123, | |
'text': 'test messsage', | |
}) | |
t = loader.get_template('email/message.txt') | |
body = t.render(c) | |
try: | |
send_mail(subject, body, '[email protected]', ['[email protected]'], fail_silently=False) | |
return HttpResponse('OK') | |
except SocketError, e: | |
return HttpResponse('ERROR') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment