I tried to send a registration completion email from Gmail with django.

I started learning Django the other day and am trying to implement a user registration feature. Send an email with Django ← I generally write the program according to this article. I got an error several times, so I will leave it as a memorandum. TemplateDoesNotExist The first thing I faced was the above error. I couldn't find the template for the title and body of the email sent when registering as a user, resulting in an error. I modified the directory as shown below and it was solved. It seems that the mail_templates folder had to be included in templates as well.

× Before correction users (app name) ├mail_templates | └create | └subject.txt (mail title template) └templates

〇 After correction users └templates  └mail_templates   └create └subject.txt (mail title template)

[WinError 10061] Could not connect because it was rejected by the target computer.

I have been rejected. This was because I tried to email the registrant from Gmail, but I didn't write the Gmail username, password, etc. in the program. I added the following to settings.py and it was solved.

settings.py


EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'Address'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True

SMTPAuthenticationError at /user_create/ Then, along with the above error, I received a warning email from Gmail, which was planned to be used as the sender in this program, saying "Someone is trying to log in illegally". This was resolved by jumping to the Google address displayed in the error and enabling access to insecure apps. (Sorry for the safety app ...)

BadHeaderError Since the line break is automatically inserted at the end of the file with the Atom I was using, an error occurred saying "Subject.txt that cannot break is in two lines! I'm in trouble!". With reference to the following site, I stopped the function to automatically start a new line and solved it. [Atom] Setting to prevent automatic line breaks at the end of the file

After resolving the above, I was able to successfully send an email using the Django app! Hooray!

Recommended Posts

I tried to send a registration completion email from Gmail with django.
I tried to create a table only with Django
I want to email from Gmail using Python.
Send email with Django
[Outlook] I tried to automatically create a daily report email with Python
I tried to extract a line art from an image with Deep Learning
I tried to draw a route map with Python
I tried collecting data from a website with Scrapy
I want to send a business start email automatically
I tried to implement a volume moving average with Quantx
[Python] Send an email from gmail with two-step verification set
I tried various methods to send Japanese mail with Python
I tried sending an email from Amazon SES with Python
I tried to automatically create a report with Markov chain
I tried to solve a combination optimization problem with Qiskit
I want to install a package from requirements.txt with poetry
I want to send a message from Python to LINE Bot
I tried to sort a random FizzBuzz column with bubble sort.
I tried to divide with a deep learning language model
I made a server with Python socket and ssl and tried to access it from a browser
I tried to make a generator that generates a C # container class from CSV with Python
Note: Send an email with Django
Easily send emails with Gmail with Django
Send email via gmail with Python 3.4.3.
A memorandum when I tried to get it automatically with selenium
[3rd] I tried to make a certain authenticator-like tool with python
[Python] A memo that I tried to get started with asyncio
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
I tried sending an email from the Sakura server with flask-mail
I tried to create Bulls and Cows with a shell program
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
I tried to cut out a still image from the video
[1st] I tried to make a certain authenticator-like tool with python
I tried to make a strange quote for Jojo with LSTM
I tried to make a mechanism of exclusive control with Go
HTML email with image to send with python
I tried to implement Autoencoder with TensorFlow
I tried to create a linebot (preparation)
I tried to visualize AutoEncoder with TensorFlow
I tried to get started with Hy
Send a message from Python to Slack
I tried sending an email with python.
I tried a functional language with Python
I tried to implement CVAE with PyTorch
I tried to make a Web API
I tried to solve TSP with QAOA
I made a WEB application with Django
I tried to introduce a serverless chatbot linked with Rakuten API to Teams
Python: I tried to make a flat / flat_map just right with a generator
[Data science basics] I tried saving from csv to mysql with python
I tried to communicate with a remote server by Socket communication with Python.
I tried to implement a blockchain that actually works with about 170 lines
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I want to send a signal only from the sub thread to the main thread
Send an email to a specific email address with python without SMTP settings
I came up with a way to make a 3D model from a photo.
I tried to create a plug-in with HULFT IoT Edge Streaming [Development] (2/3)
I tried to make a calculator with Tkinter so I will write it
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda