To send email via Python Django, we can use the EmailMesage
class.
For instance, we write
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'youremail@gmail.com'
EMAIL_HOST_PASSWORD = 'email_password'
EMAIL_PORT = 587
to add our email settings in settings.py.
Then we write
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['your@email.com'])
email.send()
to create an EmailMessage
object with the subject, body and to emails.
And then we call send
to send the email.