如何使用Django从用户的电子邮件地址发送电子邮件? [英] How do I send email from a user's email address with Django?

查看:104
本文介绍了如何使用Django从用户的电子邮件地址发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想代表用户向第三方发送电子邮件.关键是使用户的电子邮件显示为发件人:"电子邮件.

I'd like to send email to third parties on behalf of users. The key is for the user's email to show up as the "from:" email.

我尝试将send_mail与用户的电子邮件一起用作from_email,但无济于事.当我使用gmail的服务器发送邮件时,第三方将EMAIL_HOST_USER视为发件人:"电子邮件.当我尝试使用namecheap的邮件服务器时,得到了SMTPRecipientsRefused: {u'<to email>': (553, '5.7.1 <from email>: Sender address rejected: not owned by user <EMAIL_HOST_USER>')}.

I've tried using send_mail with the user's email as the from_email, but to no avail. When I used gmail's servers to send the message, the third party sees the EMAIL_HOST_USER as the "from:" email. And when I tried using namecheap's mail server, I got SMTPRecipientsRefused: {u'<to email>': (553, '5.7.1 <from email>: Sender address rejected: not owned by user <EMAIL_HOST_USER>')}.

如果可能的话,我也希望避免询问他们的密码.

If possible, I'd like to avoid asking for their password as well.

推荐答案

简短答案:您不能那样做.

Short answer: You can't do that.

在过去,无论何时有人问邮件服务器,邮件服务器过去总是很放松,但是后来发生了垃圾邮件,人们意识到检查发送电子邮件的人是否确实很重要.其地址显示在From:标头中.

Back in the old days, mail servers used to be quite relaxed about posting mail whenever anyone asked them to, but then SPAM happened and people realised that it was actually quite important to check that the person sending an email is actually the person whose address appears in the From: header.

现在有几种机制可以使欺骗发件人电子邮件地址变得非常困难.这些包括:

There are now several mechanisms in place that make it very difficult to spoof a sender email address. These include:

  1. 发件人策略框架(SPF):一种电子邮件验证系统,通过放置对从特定电子邮件地址发送电子邮件的授权IP地址的限制.如果您尝试从与电子邮件地址的合法所有者不相关的IP地址发送电子邮件,则您的邮件将被拒绝.

  1. Sender Policy Framework (SPF): An email validation system that works by placing restrictions on the IP addresses authorised to send email from a particular email address. If you try sending email from an IP address not associated with the legitimate owner of an email address, your mail will be rejected.

DomainKeys识别邮件(DKIM):一种用于确认电子邮件声称起源于特定的邮件服务器确实是源自该邮件服务器.

DomainKeys Identified Mail (DKIM): A method for confirming that emails claiming to have originated from a particular mail server really did originate from that server.

邮件传输代理限制:如今,大多数MTA都配置为仅接受来自已经认识的人的电子邮件. (这就是为什么您看到Sender address rejected: not owned by user错误消息的原因.)

Mail transfer agent restrictions: These days, most MTAs are configured to only accept emails from people who it already knows. (This is why you're seeing a Sender address rejected: not owned by user error message).

相反,最好的选择-本质上是仅 选项-是将您自己的电子邮件地址放在From:标头中,然后从您自己的邮件服务器发送电子邮件.如果您希望回复发送给其他人,请添加一个包含他们的电子邮件地址的Reply-To:标头.

Instead, your best option — essentially your only option — is to put your own email address in the From: header, and send the email from your own mail server. If you want the reply to go to someone else, add a Reply-To: header containing their email address.

这篇关于如何使用Django从用户的电子邮件地址发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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