python - SMTPSenderRefused - 553,发件人地址未验证 - Django 电子邮件表单

标签 python django email django-forms

我有一个简单的 Django 联系表(用户电子邮件、消息)。我已经配置了一个 Gmail 服务器,它可以正常工作,但它总是用 settings.py 中列出的地址重写发件人地址,正如 this answer 指出的那样以及。因此,我改为使用 Yahoo Mail 服务器配置我的设置。

这是我的settings.py文件

EMAIL_HOST = 'smtp.mail.yahoo.com'
EMAIL_HOST_USER = 'myid@yahoo.com'
EMAIL_HOST_PASSWORD = 'mypass'
EMAIL_PORT = 587
EMAIL_USE_TLS = True 

这是我的views.py

def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                'Contact Us',
                cd['message'],
                cd.get('email', ''),
                ['myid@yahoo.com'],
            )
            return HttpResponseRedirect('thanks')
    else:
        form = ContactForm()
    return render(request, 'hunt/contact.html', {'form': form})

现在我收到一个SMTPSenderRefused 异常。

异常值 - (553, '发件人地址未验证 - 请参阅 http://help.yahoo.com/l/us/yahoo/mail/original/manage/sendfrom-07.html', '某人@gmail.com')

编辑 - 我尝试将自己的 ID myid@yahoo.com 放入电子邮件字段,但它成功了。它似乎只适用于我的电子邮件 ID。

最佳答案

几乎所有公共(public)邮件服务器只允许在 From header 中包含实际作者电子邮件的电子邮件。您正尝试使用“发件人:some_user@email.com”发送电子邮件,但已被拒绝。真的,这很像您在 Google 上遇到的问题,但 Yahoo 会抛出一个错误,而不是悄悄地弄乱 header 。

我会在这里将用户的电子邮件放入消息正文中,并且可能会尝试将其放入“回复”中 header manually .

附言通常最好为每个可能的函数使用命名关键字参数(在您的情况下 - send_mail)。它通常有助于避免愚蠢的参数顺序错误。

关于python - SMTPSenderRefused - 553,发件人地址未验证 - Django 电子邮件表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20808158/

相关文章:

python - numpy 数组 : efficient way to compute argmax within a fixed window at a set of rows and columns given as input

django - 通过管理小部件将不正确的经度/纬度保存到 PointField

php - 隐藏或不打印来自服务器的消息

python - Django 和 SSL 问题

python - Tkinter 顶层 : Opening treeview to fit the frame

python - 在 python 中按频率值排序列表

python - 模板中的删除按钮处于非事件状态

django - Python 3.4 Django 'QueryDict'对象没有属性 'iterkeys'

ios - IOS 7中的电子邮件地址验证

vba - 使用 VBA 以编程方式更改 Outlook 中电子邮件正文的属性