Matthew Dresser
Matthew Dresser

Reputation: 11442

MailMessage.From.DisplayName not behaving as expected with SmtpClient.Send()

I am using the following code to send an email in .Net2.0.

MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]", "[email protected] on behalf of someone else");
message.To.Add("[email protected]");
message.IsBodyHtml = true;
message.Body = "some actual html here, not just a string literal"
message.Subject = "Alert email from www.mydomain.com";

SmtpClient client = new SmtpClient("MySmtpClient.com", 25);
client.Send(message);

The problem I am experiencing is that when I check my email inbox, the from field of the email shows "[email protected]" and not "[email protected] on behalf of someone else", i.e. it's showing just the from email address instead of the DisplayName.

I've tried setting message.ReplyTo the same as I've set message.From but this seems to make no difference.

Am I missing something here?

Upvotes: 2

Views: 2297

Answers (1)

dave wanta
dave wanta

Reputation: 7214

Try adding a Sender header.

For example:

message.Headers.Add( "Sender", "[email protected]" )

Upvotes: 1

Related Questions