Basically, this shape seems to be fine. If you don't have an SMTP server, it seems to be set on the back end, but I'm studying.
views.py
import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
from django.http import (HttpResponse, HttpResponseRedirect,)
from django.core.mail import (send_mail, BadHeaderError,)
#source virtualenv/bin/activate
def send_mail(request):
subject = request.POST.get('subject','')
message = request.POST.get('message','')
if subject and message:
try:
send_mail(subject,message)
except BadHeaderError:
return HttpResponse('Error')
return HttpResponseRedirect('index.html')
else:
return HttpResponse('Please fill in all items')
Recommended Posts