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@gmail.com"
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 = "siberlab01@gmail.com"
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','siberlab01@gmail.com', ['siberlab01@gmail.com'], 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
  • ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True. I have only EMAIL_USE_TLS=True – Sergei Sokov Feb 23 '21 at 12:45
  • I said change the fail_silently = true or false. I dont say 'EMAIL_USE_TLS = True' . send_mail('django test mail', 'this is django','siberlab01@gmail.com', ['siberlab01@gmail.com'], fail_silently = False ) or send_mail('django test mail', 'this is django','siberlab01@gmail.com', ['siberlab01@gmail.com'], fail_silently = True) – arif Feb 23 '21 at 12:56
  • I want to tell about firstly you try with shell command. Becouse when your email sending configuration is correct, your send_mail function maybe is not correct in the project. Therefore, you should try shell command – arif Feb 23 '21 at 13:01
  • I did this - send_mail('django test mail', 'this is django','noreply@raketaweb.eu ', ['noreply@raketaweb.eu '], fail_silently = True ) and I still have ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True. And – Sergei Sokov Feb 23 '21 at 13:06
  • what happen fail_silently = false like this: send_mail('django test mail', 'this is django','noreply@raketaweb.eu ', ['noreply@raketaweb.eu '], fail_silently = False) – arif Feb 23 '21 at 13:13
  • I did that in the shell, and I have this error – Sergei Sokov Feb 23 '21 at 13:16
  • if fail_silently = False, ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True – Sergei Sokov Feb 23 '21 at 13:28
  • if fail_silently = True, ValueError: EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set one of those settings to True – Sergei Sokov Feb 23 '21 at 13:29
  • I want to ask that is 'noreply@raketaweb'.eu mail domain and gmail domain same feature? – arif Feb 23 '21 at 13:34
  • I just changed, but this email is working on my local server, if you whould like I can change it to gmail. I did it beacase my hosting doesn't want check it for gmail – Sergei Sokov Feb 23 '21 at 13:44
  • I think change your account. Becouse ı try with gmail account and maybe my modification and configuration only belongs to the gmail account. – arif Feb 23 '21 at 13:47
  • my new answer is the solution to your error – arif Feb 23 '21 at 13:49
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('yourEmailAddress@gmail.com', 'yourEmailPassword')

    try:
        server.sendmail('yourEmailAddress@gmail.com', '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