Django - 电子邮件未发送,但其 object 是在数据库中创建的

Django - Email is not sent but its object is created in DB

当我尝试通过 django 发送电子邮件时,我注意到创建了 object 的电子邮件并且所有字段(电子邮件、标题、body)都在其中,但实际的电子邮件不是发送。 当我检查芹菜日志时,我看到以下消息:

SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted.
Learn more `at\n5.7.8  https://support.google.com/mail/?p=BadCredentials` 

但我 100% 确定我使用了正确的凭据并且我的邮箱没有受到两个因素的保护 认证

中的代码

settings.py

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_PORT = 587
EMAIL_HOST_USER = '*******@gmail.com' # my email, I'm sure it's correct
EMAIL_HOST_PASSWORD = '********' # my password, I'm sure it's correct

中的代码

views.py

(我收集所需信息的联系表 - 电子邮件、职位、body)

class ContactUs(CreateView):
    template_name = 'my_profile.html'
    queryset = Contact.objects.all()
    fields = ('email', 'title', 'body')
    success_url = reverse_lazy('index')

    def form_valid(self, form):
        response = super().form_valid(form)

        message = form.cleaned_data.get('body')
        subject = form.cleaned_data.get('title')
        email_from = form.cleaned_data.get('email')
        recipient_list = [settings.EMAIL_HOST_USER, ]

        send_email_async.delay(subject, message, email_from, recipient_list)

        return response

中的代码

tasks.py

(芹菜)

@shared_task()
def send_email_async(subject, message, email_from, recipient_list):
    send_mail(subject, message, email_from, recipient_list, fail_silently=False)

但它是否是芹菜并不重要 - 电子邮件不会自行发送,但我在我的 Postgres 数据库中看到了这封电子邮件的 object

Django 版本 2.2.10

您已设置仅将电子邮件记录到控制台的控制台后端:

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

您需要使用 smtp 后端:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'