错误消息中有解释。由于
randomacc@hotmail.com您已从联系表中获取发件人地址,因此您的电子邮件主机拒绝了该电子邮件。
相反,您应该使用自己的电子邮件地址作为发件人地址。您可以使用该
reply_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()编辑:
在注释中,您询问了如何在邮件正文中包含发件人的地址。在
message和
from_email仅仅是字符串,这样你就可以将它们组合起来,但是你想您发送电子邮件之前。
注意,您不应该
from_email从cleaned_data中获取参数。您知道
from_address应当为
test@test.megiteam.pl,因此可以使用它,也可以
DEFAULT_FROM_EMAIL从您的设置中导入。
请注意,如果您使用
EmailMessage上面的示例创建消息,并将回复设置为标题,那么当您点击回复按钮时,您的电子邮件客户端应该做正确的事情。以下示例用于
send_mail使其与链接到的代码相似。
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: %smessage: %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'], )



