[PYTHON] Note: Send an email with Django

Send an email with Django

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

Note: Send an email with Django
Send email with Django
[Python] Send an email with outlook
Send an email with Amazon SES + Python
Send an email to Spushi's address with python
Send an email with Excel attached in Python
Send Japanese email with Python3
Send an email with a user other than EMAIL_HOST_USER written in settings in django
[boto3] Send an email using SES
Django note 4
Load Django modules with an interpreter
[Python] Send an email from gmail with two-step verification set
[Automation] Send Outlook email with Python
Django Note 5
Django Note 1
Django note 3
Django note 2
Easily send emails with Gmail with Django
Send email via gmail with Python 3.4.3.
HTML email with image to send with python
Browse an existing external database with Django
Note when creating an environment with python
I tried sending an email with python.
Create an update screen with Django Updateview
A note on enabling PostgreSQL with Django
What to do if you couldn't send an email to Yahoo with Python.
Send an email to a specific email address with python without SMTP settings
[Python] Send email
[Python] Send email
CRUD with Django
I tried to send a registration completion email from Gmail with django.
I tried sending an email with SendGrid + Python
To automatically send an email with an attachment using the Gmail API in Python
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Procedure for creating an application with Django with Pycharm ~ Preparation ~
Output PDF with Django
Markdown output with Django
Use Gentelella with django
Twitter OAuth with Django
Reading Note: An Introduction to Data Analysis with Python
Getting Started with Django 1
File upload with django
Use LESS with Django
Validate E-Mail with Python
Pooling mechanize with Django
Use MySQL with Django
If you can't send an email with python smtplib and have trouble, command line
Start today with Django
Getting Started with Django 2
It's too easy to use an existing database with Django
I tried sending an email from Amazon SES with Python
Code to send an email based on the Excel email list
I'm trying to create an authentication / authorization process with Django
Create an authentication feature with django-allauth and CustomUser in Django
Create a Todo app with Django ① Build an environment with Docker
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Get started with Django! ~ Tutorial ⑤ ~
Create an environment with virtualenv
Minimal website environment with django