Settings.py
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAILL_USE_TLS = True
views.py
print('Helloo')
send_mail(
'Testing',
'Hi',
'[email protected]',
['[email protected]'], #my personal gmail id
fail_silently=False,
)
print('Hiiii')
When i run this code, only Helloo
is getting printed, I've imported send_mail as well,tried using smtplib as well but that was giving smpt auth extension error so i'm trying send_mail method but it also doesn't seem to work, don't know what is the exact issue.
CodePudding user response:
try this
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'emailId'
EMAIL_HOST_PASSWORD = 'password'
CodePudding user response:
Need to set Following configuration in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = 'xyz.gmail.com' # sender's email-id
EMAIL_HOST_PASSWORD = 'xyz' # password associated with above email-id
I think you forgot EMAIL_BACKEND.
To send mail add following code
from django.conf import settings
from django.core.mail import send_mail
subject = 'email subject'
message = 'Hi , Thank you for your help.'
email_from = settings.EMAIL_HOST_USER
recipient_list = [user.email, ] # email to send
send_mail( subject, message, email_from, recipient_list )
If you are using gmail for sending mails then you need to turn on Less Secure App Access
. The option is present in Manage Your Account
in gmail.
I hope it will help you.