Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误:SMTPrecipientsrefuse553和#x27;5.7.1#在django编写联系表时_Python_Django_Smtp_Sendmail - Fatal编程技术网

Python 错误:SMTPrecipientsrefuse553和#x27;5.7.1#在django编写联系表时

Python 错误:SMTPrecipientsrefuse553和#x27;5.7.1#在django编写联系表时,python,django,smtp,sendmail,Python,Django,Smtp,Sendmail,我试图在django 1.3和python 2.6中创建一个联系人表单 以下错误的原因是什么 错误: SMTPRecipientsRefused at /contact/ {'test@test.megiteam.pl': (553, '5.7.1 <randomacc@hotmail.com>: Sender address rejected: not owned by user test@test.megiteam.pl')} 编辑:如果djangobook后面有任何其他内容,

我试图在django 1.3和python 2.6中创建一个联系人表单

以下错误的原因是什么

错误:

SMTPRecipientsRefused at /contact/
{'test@test.megiteam.pl': (553, '5.7.1 <randomacc@hotmail.com>: Sender address
rejected: not owned by user test@test.megiteam.pl')}
编辑:如果djangobook后面有任何其他内容,则这是导致该内容的部分:

        send_mail(
            request.POST['subject'],
            request.POST['message'],
            request.POST.get('email', 'noreply@example.com'), #get rid of 'email'
            ['siteowner@example.com'],

解释在错误消息中。由于发件人地址
randomacc@hotmail.com
您从联系人表单中获取的信息

相反,您应该使用自己的电子邮件地址作为发件人地址。您可以使用
reply\u to
选项,以便将答复发送给您的用户

email = EmailMessage(
    'Subject',
    'Body goes here',
    'test@test.megiteam.pl',
    ['to@example.com',],
    reply_to='randomacc@hotmail.com',
)
email.send()
在Django 1.7及更早版本中,没有
reply_to
参数,但您可以手动设置
reply to
标题:

email = EmailMessage(
    'Subject',
    'Body goes here',
    'test@test.megiteam.pl',
    ['to@example.com',],
    headers = {'Reply-To': 'randomacc@hotmail.com'},
)
email.send()
编辑: 在评论中,您询问了如何在邮件正文中包含发件人的地址。电子邮件中的
消息
只是字符串,因此您可以在发送电子邮件之前将它们组合在一起

请注意,您不应该从已清理的\u数据中获取
from\u email
参数。您知道
from\u地址应该是
test@test.megiteam.pl
,所以使用它,或者从您的设置中从电子邮件导入
默认值

请注意,如果您像上面的示例一样使用
EmailMessage
创建邮件,并将回复设置为标题,那么当您点击回复按钮时,您的电子邮件客户端应该做正确的事情。下面的示例使用
send\u mail
使其与


想删除,但另一方面我不想让你没有+点:)谢谢不要删除--这将帮助下一个在谷歌搜索
smtprecipientsreference
:)嗯,考虑到我在使用此代码,我有一个问题想问你:我如何在发送的邮件正文中附加发件人电子邮件地址(或任何其他附加字段)?
email = EmailMessage(
    'Subject',
    'Body goes here',
    'test@test.megiteam.pl',
    ['to@example.com',],
    headers = {'Reply-To': 'randomacc@hotmail.com'},
)
email.send()
from django.conf import settings

...
    if form.is_valid():
        cd = form.cleaned_data
        message = cd['message']
        # construct the message body from the form's cleaned data
        body = """\
from: %s
message: %s""" % (cd['email'], cd['message'])
        send_mail(
            cd['subject'],
            body,
            settings.DEFAULT_FROM_EMAIL, # use your email address, not the one from the form
            ['test@test.megiteam.pl'],
        )