Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Last active May 14, 2021 20:01
Show Gist options
  • Save rturowicz/5227981 to your computer and use it in GitHub Desktop.
Save rturowicz/5227981 to your computer and use it in GitHub Desktop.
django - send email
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