Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailMessage, difference between Sender and From properties

I've been using the System.Net namespace 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 Sender and the From properties in the MailMessage class?

Are they both the same, and if not is there a reason to use Sender together with 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
like image 569
Freek Buurman Avatar asked Apr 19 '10 15:04

Freek Buurman


2 Answers

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.

Sender: Address of the actual sender acting on behalf of the author listed in the From: field (secretary, list manager, etc.).

Details on 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).

like image 194
ntziolis Avatar answered Oct 23 '22 13:10

ntziolis


I found this explanation 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.

like image 28
Jeremy Wiggins Avatar answered Oct 23 '22 13:10

Jeremy Wiggins