Can not send mail

112 views
Skip to first unread message

Kerem Üllenoğlu

unread,
Aug 4, 2023, 8:55:49 AM8/4/23
to Django users

Hi.

I was trying to use Django's accounts system and configured some templates. When I tried to do password reset, it said "SMTPRecipientsRefused at /accounts/password_reset/". But it works when I send an email with smtplib.

In Django settings:

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" 
EMAIL_HOST = "mail.X.com" 
EMAIL_PORT = 587 
EMAIL_HOST_USER = "....@mydomain" 
EMAIL_PASSWORD = "password"

And the error:

Exception Type: SMTPRecipientsRefused at /accounts/password_reset/ Exception Value: {'....@gmail.com': (450, b'4.7.1 We do not relay gmail.com')}

But i knew i used the same mail before with smtplib and tried again, and it worked.

>>> import smtplib
>>> from email.message import EmailMessage
>>> mail_server = "mail.X.com"
>>> mail_username = "...@mydomain"
>>> mail_password = "password"
>>> mail_port = 587
>>> msg = EmailMessage()
>>> msg["Subject"] = "subject test"
>>> msg["From"] = mail_username
>>> msg["To"] = "....@gmail.com"
>>> server = smtplib.SMTP(mail_server, mail_port)
>>> server.login(mail_username, mail_password) 
(235, b'2.7.0 Ok')
>>> server.send_message(msg)
 {}
>>> server.quit() 
(221, b'2.0.0 Bye')

I tried adding DEFAULT_FROM_EMAIL = "...@mydomain" to the settings.py, but it didn't make any difference.
I tried adding EMAIL_USE_TLS=True, but it said:

SSLCertVerificationError at /accounts/password_reset/ [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'mail.X.com'. (_ssl.c:1131)

I don't know what is the problem. Is it because of Django or something from mail server. It is a mail account that my company bought for the project.
Thanks for the answers.

Kerem Üllenoğlu

unread,
Aug 6, 2023, 7:36:00 AM8/6/23
to Django users

Hey,
I changed `EMAIL_PASSWORD` to `EMAIL_HOST_PASSWORD` and added the `DEFAULT_FROM_EMAIL`, now it works.
See my Stack Overflow question. I don't understand why the server said "We do not relay gmail.com" if there is a problem with the password.
Have a good day, everyone.
4 Ağustos 2023 Cuma tarihinde saat 12:55:49 UTC itibarıyla Kerem Üllenoğlu şunları yazdı:
Reply all
Reply to author
Forward
0 new messages