I am using python Django to send mail to a user when user login and using django.core.mail(send mail) but it's working on localhost and successfully sending emails to the user but when I host my site on Heroku it's giving some errors.
settings.py
# email config
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # During deployment only
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = 587
EMAIL_HOST_USER = config('EMAIL_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_USER_PASSWORD')
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'Masjid Matrimonial Team <noreply#example.com>'
Views.py
currenttime=datetime.now()
subject = "New Login Alert"
message="You have loged into your account on "+ currenttime.strftime('%A %d %B,%Y %I:%M %p')
recipient_list = [useris.appuser.email]
send_mail( subject, message, email_from, recipient_list )email_from = settings.EMAIL_HOST_USER
SMTP Error code 534 5.7.14 means Authorization error.
Try to activate sending via less secure apps via https://myaccount.google.com/lesssecureapps
Related
I am using cpanel email on gmail. But when sending mails through Django EmailAlternatives, the mail being sent is reported as dangerous. How do I make it safe, or if I am using PORT 465 and HOST as smtp.gmail.com, it is not working. Below given are my EMAIL Details.
WSGI_APPLICATION = 'backend.wsgi.application'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.my_dot_in_domain'
EMAIL_HOST_USER = 'my_email'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
Screenshot to explain what mail says and all the details
I am trying to send mail via Django, but have an error: (501, b'5.1.7 Invalid address', '"emea\\\\sss1ss1"')
My EMAIL_HOST_USER = r'emea\xss1ss1'. As you can see my user consist \x so I am using r''. How to fix it, the real EMAIL_settings are correct.
my view.py
def home(request):
subject = 'Test mailing'
message = 'Hello world!!!'
email_from = settings.EMAIL_HOST_USER
recipient_list = ['smth#smth.com']
send_mail(subject,message,email_from,recipient_list)
return HttpResponse('Test mailing')
well if you want to send an email using Django, first you have to set some variables in settings.py.
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com' # for zoho mail service. use smtp.gmail.com for Gmail.
EMAIL_HOST_USER = 'something#something.com'
EMAIL_HOST_PASSWORD = 'something'
DEFAULT_FROM_EMAIL = f'Your Name {EMAIL_HOST_USER}'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
then import send_mail function and settings:
from django.core.mail import send_mail
from your_project import settings
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user_email, ],)
I set up everything as the Django documentation but when I test sending an email.It works but When I check my inbox I find out that I sent and revived from to the same email address.
Here is the 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 = "myemail#gmail.com"
EMAIL_HOST_PASSWORD = "mypassword"
And the views.py
...
send_mail( 'subject', 'message', 'user#gmail.com', ['myemail#gmail.com',], fail_silently=False, )
...
But I received an email from myemail#gmail.com to me(myemail#gmail.com).
Im not sure if you did this already but if youre using gmail then you will need to do the following.
Sign in to your Google Admin console (Sign in using an administrator account)
Click Security > Less secure apps.
Select Allow users to manage their access to less secure apps.
Click Save.25
Also you should use environment variables for the email address if you are live already eg:
EMAIL_HOST_USER = os.environ.get('MY_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('MY_EMAIL_PASS')
If its all working and you are just getting the mail to the wrong address can you send on the document you followed?
In terms of you settings.py that looks fine to me.
Getting the error message
SMTPAuthenticationError at /accounts/signup/teacher/ (530, b'Must
issue a STARTTLS command first')
when trying to test the signup process in my django app. What should happen is that a user who signs in should receive a confirmation email after signing up.
Here are my settings
EMAIL_BACKED = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_PORT = 587
EMAIL_USER_TLS = True
EMAIL_HOST_USER = '***#***.com'
EMAIL_HOST_PASSWORD = '***'
I am using privateemail from namecheap to send the confirmation emails
I set up django email backend following way:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# Host for sending e-mail.
EMAIL_HOST = 'mytdl.de'
# Port for sending e-mail.
EMAIL_PORT = 25
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = 'me#mytdl.de'
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
But sending emails with django-allauth will return following error:
(535, b'5.7.8 Error: authentication failed: authentication failure')
Testing the the settings with
telnet mytdl.de 25
or Thunderbird as email client works fine.
2.7.0 Authentication successful
But Django / SMTP stills throws that error.
Django also tries to
AUTH CRAM-MD5
and not
AUTH LOGIN
any ideas?
If your email host is gmail then you can fix it with these simple steps:
Login to your gmail account (The one you are using in your Django application for sending mails ).
Then select Account from google apps or click here.
On your control panel click on Apps with account access under Sign-in & security.
Then scroll down and enable Allow less secure apps
Also maintain your settings variables in this order:
settings.py
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'example#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587