'Django - Add a confirmation email fuction [closed]
So I have a fully working signup page so far.
I want to add a simple confirmation email function, that sends an email to the user to inform about the successful creation of his account.
I don't necessarily need any extra functions like a verification link in the email to activate the account.
I have been looking at tutorials online, though they all seem to already have a registration feature built in (which our project already has).
As long as we just need that verification function, can you provide me some directions to explore further to make this addition?
I am new to Django
and do not have a full understanding of what I am doing.
I'm working with:
- Django version = 4.0.2
- Python version = 3.9
Solution 1:[1]
In your settings.py
You can add the following to send email...
# Email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'p@55w0rd'
Then in your project/views.py
call following at the end of func/method to send...
from django.core.mail import send_mail
send_mail(subject, message, '[email protected]', '[email protected]')
sent = True
Here are the docs... https://docs.djangoproject.com/en/4.0/topics/email/
Solution 2:[2]
Thanks everyone! I figured it out; I made a function in the views .py, imported it at the top of views.py, called it in the register.html (where the submit button is), and used the settings.py file to specify email settings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Blake Kinnaman |