0

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"
Sergei Sokov
  • 46
  • 2
  • 8
  • go to your gmail account > security allow less secure app. it will help. google by default block emails sent by unknown devices. https://support.google.com/accounts/answer/6010255 – harshil suthar Feb 23 '21 at 10:36

4 Answers4

1

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

yulaf
  • 41
  • 1
  • 3
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '22 at 14:34
0

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"
arif
  • 16
  • 3
0

can you write 'python manage.py shell' in your terminal screen? After that

  1. 'from django.core.mail import send_mail' enter
  2. 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.

enter image description here

arif
  • 16
  • 3
0

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()
arif
  • 16
  • 3
  • This method is working. Thank you so much. But I have a problem with encoding. Peaple will write by Russian language. What shoud I do with this problem? – Sergei Sokov Feb 23 '21 at 15:13
  • what is the other problem. Could you give a example? If you want to open new stackoverflow error, I will look. Please send url this place – arif Feb 23 '21 at 15:34
  • https://stackoverflow.com/questions/66337145/unicodeencodeerror-ascii-codec-cant-encode-character-in-position-0-4-ordina – Sergei Sokov Feb 23 '21 at 16:29