.net MailMessage,Sender 和 From 属性的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2668721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MailMessage, difference between Sender and From properties
提问by Freek Buurman
I've been using the System.Netnamespace ever since we switched from .NET Framework 1.1 to the 3.5 framework, but there’s one thing that’s been puzzling me since. What's the difference between the Senderand the Fromproperties in the MailMessageclass?
System.Net自从我们从 .NET Framework 1.1 切换到 3.5 框架以来,我一直在使用命名空间,但从那以后,有一件事情一直让我感到困惑。Sender和类中的From属性有什么区别MailMessage?
Are they both the same, and if not is there a reason to use Sendertogether with From?
它们是否相同,如果不同,是否有理由与Sender一起使用From?
For example:
例如:
Using m As New System.Net.Mail.MailMessage()
m.Sender = New System.Net.Mail.MailAddress("[email protected]", "Name here")
m.From = New System.Net.Mail.MailAddress("[email protected]", "Name here")
m.Subject = "Test"
m.Body = "Test"
Dim client As New System.Net.Mail.SmtpClient("mymailserver.com")
client.Send(m)
End Using
采纳答案by ntziolis
Excerpt from the wiki on email:
电子邮件中的维基摘录:
Header fields: The message header should include at least the following fields:
标题字段:消息标题至少应包括以下字段:
From:The e-mail address, and optionally the name of the author(s). In many e-mail clients not changeable except through changing account settings.
发件人:电子邮件地址,以及作者姓名(可选)。在许多电子邮件客户端中,除非通过更改帐户设置,否则无法更改。
Also note that the "From:" field does not have to be the real sender of the e-mail message. One reason is that it is very easy to fake the "From:" field and let a message seem to be from any mail address. It is possible to digitally sign e-mail, which is much harder to fake, but such signatures require extra programming and often external programs to verify. Some ISPs do not relay e-mail claiming to come from a domain not hosted by them, but very few (if any) check to make sure that the person or even e-mail address named in the "From:" field is the one associated with the connection. Some ISPs apply e-mail authentication systems to e-mail being sent through their MTA to allow other MTAs to detect forged spam that might appear to come from them.
另请注意,“发件人:”字段不必是电子邮件的真正发件人。一个原因是很容易伪造“发件人:”字段并让邮件看起来来自任何邮件地址。可以对电子邮件进行数字签名,这更难伪造,但此类签名需要额外的编程,而且通常需要外部程序来验证。一些 ISP 不会中继声称来自非他们托管的域的电子邮件,但很少(如果有)检查以确保“发件人:”字段中指定的人或什至电子邮件地址是一个与连接相关联。一些 ISP 将电子邮件身份验证系统应用于通过其 MTA 发送的电子邮件,以允许其他 MTA 检测可能来自他们的伪造垃圾邮件。
Sender:Address of the actual senderacting on behalf of the author listed in the From: field (secretary, list manager, etc.).
发件人:代表发件人:字段中列出的作者行事的实际发件人的地址(秘书、列表管理员等)。
Details on http://en.wikipedia.org/wiki/Email
http://en.wikipedia.org/wiki/Email 上的详细信息
For example gmail uses the from/sender fields to send emails from different email adresses than your gmail account (After verification).
例如,gmail 使用发件人/发件人字段从与您的 Gmail 帐户不同的电子邮件地址发送电子邮件(验证后)。
回答by Jeremy Wiggins
I found thisexplanation to be pretty easy to understand (emphasis mine).
我发现这个解释很容易理解(强调我的)。
One area in which there is quite a variety of operation is in the concept of the From Address of an email and the Sender of the email.
Some email servers will accept the From Address as being the Sender, and some deduce the Sender automatically, and some require the Sender to be specified explicitly.
In general, the Sender is the actual originator of the email message. The From Address, in contrast, is simply a header line in the email that may or may not be taken to mean anything.The From Address can often be left out completely. Spammers can easily spoof the From Address. ISPs try to ensure that spammers cannot spoof the Sender.
一个涉及多种操作的领域是电子邮件的发件人地址和电子邮件的发件人的概念。
有些电子邮件服务器会接受发件人地址作为发件人,有些会自动推断出发件人,而有些则要求明确指定发件人。
通常,发件人是电子邮件消息的实际发起者。相比之下,发件人地址只是电子邮件中的一个标题行,可能会也可能不会被视为任何含义。发件人地址通常可以完全省略。垃圾邮件发送者可以轻松欺骗发件人地址。ISP 试图确保垃圾邮件发送者无法欺骗发件人。

