MailMessage
Sender vs From
email properties
.NET programming
C# email handling

MailMessage, difference between Sender and From properties

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In System.Net.Mail.MailMessage, From and Sender are related but not identical. From describes the authoring address of the message, while Sender is used when the message is actually being sent by a different mailbox on behalf of that author.

Use From as the Primary Author Address

From is the address most recipients think of as "who the message is from." It is the main mailbox associated with the message content.

csharp
1using System.Net.Mail;
2
3var message = new MailMessage();
4message.From = new MailAddress("[email protected]", "Billing Team");
5message.To.Add("[email protected]");
6message.Subject = "Invoice ready";
7message.Body = "Your invoice is ready to download.";

In this example, the recipient sees the message as coming from the Billing Team. If you stop here and do not set Sender, the From address is both the visible author and the effective sending identity represented by the message headers.

Use Sender for "On Behalf Of" Scenarios

Sender matters when one mailbox or system sends mail on behalf of another. A common example is an automated service or delegated assistant sending a message that should still appear to come from a team mailbox.

csharp
1using System.Net.Mail;
2
3var message = new MailMessage();
4message.From = new MailAddress("[email protected]", "Sales Team");
5message.Sender = new MailAddress("[email protected]", "Notification Service");
6message.To.Add("[email protected]");
7message.Subject = "Demo follow-up";
8message.Body = "Thanks for your interest. We will contact you shortly.";

Here, From says the message is from the Sales Team, but Sender says the actual sending agent is the notification service. Some mail clients expose this as wording similar to "sent on behalf of."

This distinction is useful when:

  • A service account delivers mail for a shared mailbox
  • An assistant sends mail on behalf of an executive
  • Infrastructure sends messages for an application identity that users should recognize

Keep ReplyToList Separate in Your Design

Developers sometimes confuse Sender with the place replies should go. That is a different concern. If you want replies to land somewhere else, use ReplyToList.

csharp
1using System.Net.Mail;
2
3var message = new MailMessage();
4message.From = new MailAddress("[email protected]", "System Notifications");
5message.ReplyToList.Add(new MailAddress("[email protected]", "Support Team"));
6message.To.Add("[email protected]");
7message.Subject = "Password changed";
8message.Body = "Your password was changed successfully.";

In this case, the message still comes from [email protected], but replies are directed to support. That is independent of whether Sender is set.

Think in Terms of Email Headers

A useful mental model is:

  • 'From: the mailbox the message claims to be authored by'
  • 'Sender: the mailbox that actually sent it when different'
  • 'ReplyToList: the mailbox that should receive replies'

Those are separate pieces of metadata, and using the correct property makes your intent clear both to mail systems and to other developers reading the code.

Common Pitfalls

The most common mistake is setting Sender when ReplyToList was actually intended. If your goal is "reply somewhere else," then Sender is the wrong tool.

Another issue is expecting every mail client to display Sender prominently. Many clients emphasize From and only reveal sender details when they differ or when the user expands the full headers. The header is still meaningful even if the UI does not always surface it.

It is also easy to forget that your SMTP infrastructure must allow the chosen combination of addresses. If you set From to one domain and the actual sending account is not authorized to send on its behalf, the message can be rejected or flagged by mail authentication checks.

Finally, avoid setting both properties without a reason. If there is no delegated or on-behalf-of scenario, keeping only From makes the message simpler and easier to understand.

Summary

  • 'From is the primary author identity of the email.'
  • 'Sender is used when a different mailbox or service sends the message on behalf of From.'
  • 'ReplyToList controls where replies go and is not the same as Sender.'
  • Some email clients display Sender as an "on behalf of" detail when it differs from From.
  • Use Sender only when delegation or delivery indirection is part of the design.

Course illustration
Course illustration

All Rights Reserved.