Django send_mail SMTPSender使用gmail拒绝530 [英] Django send_mail SMTPSenderRefused 530 with gmail

查看:128
本文介绍了Django send_mail SMTPSender使用gmail拒绝530的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一段时间,以便能够从我正在开发的网站上接收Django的电子邮件.现在,我还没有部署它,并且我正在使用Django Development Server,并且我不知道这是否会影响它.

I've been trying for some time to be able to receive emails with Django from a website I'm developing. Now, I haven't deployed it yet, and I am using the Django Development Server, and I don't know if this affects it.

这是我的settings.py配置:

Here is my settings.py configuration:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'my_email@gmail.com'
EMAIL_HOST_PASSWROD = 'my_password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
DEFAULT_TO_EMAIL = EMAIL_HOST_USER

然后,通过项目的根文件夹运行python manage.py shell,然后键入以下内容:

Then, through the root folder of the project I run python manage.py shell, and type the following:

>>> import django
>>> from django.conf import settings
>>> from django.core.mail import send_mail
>>> send_mail('test', 'test', settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER], fail_silently=False)

我收到的是以下错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/paulo/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/paulo/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/mail/message.py", line 348, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/paulo/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 111, in send_messages
    sent = self._send(message)
  File "/home/paulo/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 127, in _send
    self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
  File "/home/paulo/anaconda3/envs/MyDjangoEnv/lib/python3.6/smtplib.py", line 866, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1  https://support.google.com/mail/?p=WantAuthErrorv11sm8729581qkl.88 - gsmtp', 'my_email@gmail.com')

我已启用允许安全性较低的应用程序的选项.

I have enabled the option to allow less secure applications.

在尝试使用两步验证时,我尝试输入google提供的EMAIL_HOST_PASSWORD ="my_password"而不是EMAIL_HOST_PASSWORD ="my_password".没用.

I tried, when using 2-step verification, to input, instead of EMAIL_HOST_PASSWORD = "my_password", to input EMAIL_HOST_PASSWORD = 'myapplicationpassword' provided by google. It didn't work.

然后,我禁用了两步验证,并将应用程序密码更改回我的实际密码,并且错误仍然存​​在.

Then I have disabled the 2-step verification and changed from the application password back to my actual password, and the error remains.

我做错什么了吗? Google是否以某种方式阻止了这些类型的应用程序?如果我运行自己的邮件服务器,我会做得更好吗?

Am I doing something wrong? Has Google somehow blocked these types of application? Would I do better if I ran my own mail server?

推荐答案

请确保您执行以下两项操作:

Make sure that you do the following two things:

  1. 转到应用密码进行两步验证,或查看缺乏安全的应用访问权限"如果您不使用MFA. google设置时提供的密码是一个16位数字的代码,其中包含空格,它们会计算在内.
  1. Go to App passwords for 2-factor authentication, or look into "Less secure app access" if you're not using MFA. The password google provides when setting up as is a 16 digit code that includes spaces, they count.

  1. 确保导入的设置或设置和/或获取的密码在同一终端外壳中:

  1. Make sure the settings imported or password set and/or retrieved is in the same terminal shell:

EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD')

export EMAIL_PASSWORD="xxxx xxxx xxxx xxxx"

这篇关于Django send_mail SMTPSender使用gmail拒绝530的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆