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)
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