'Django does't send email on the remote server
I am trying to send an email when a user fills out a form on my site. Everything works on my local server, letters are sent. On a remote timeweb.com server with the same settings, letters are not sent and I am got them. Tried DEBUG = False and True I tried different mail services: gmail, mail, yandex, timeweb mail. In gmail included "Unreliable applications that have access to the account". And here I included https://accounts.google.com/DisplayUnlockCaptcha Nothing helps.
Who knows, please tell me where to dig.
'setting.py'
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = "Your_Password"
Solution 1:[1]
when ? researched your error ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL....., ? find another email sending code. I rocemmend you to read this link SMTP issue in Django web application. Can you try this:
import smtplib
def sendEmail():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'yourEmailPassword')
try:
server.sendmail('[email protected]', 'emailAddressBeingSentTo', 'messageBeingSent')
except:
print('An error occurred when trying to send an email')
server.quit()
Solution 2:[2]
I am using this email sending situation. This is working my project. I saw this method in https://www.youtube.com/watch?v=UH8oHNDfTyQ. If you want to look this url, it work in your project.
'setting.py'
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = "Your_Password"
Solution 3:[3]
can you write 'python manage.py shell' in your terminal screen? After that
- 'from django.core.mail import send_mail' enter
- send_mail('django test mail', 'this is django','[email protected]', ['[email protected]'], fail_silently = False )
in 2 section change your gmail account. ?f you try this implementation, can you write which number do you see? If this number is 0, change fail_silently part with true. If you see 0 number again, this is not working again.
My answer is okey with this same configuration. Look my image.
Solution 4:[4]
its a little late but I solved this way:
I saw a warning when I checked my Google account, its about new login. Its says: "Detected new login!" and gave two choice; It's me - It's not me.
and when I chose 'It's me', my server started the sending email.
Also my settings just like yours
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 | arif |
Solution 3 | arif |
Solution 4 | yulaf |