Monday, June 26, 2017

SMTP Friendly Name in 3 different places — still doesn't show

Leave a Comment

I have specified the SMTP friendly name in my code and in my web.config file, but once the email gets sent, the friendly name is not there. Please see my setup below. In all these instances, I've tried both "Friendly Name" <email@email.com> (with quotes) as well as Friendly Name <email@email.com> (without quotes), but neither makes a difference; both show up in inbox as being from the email address, no friendly name.

Here's IIS: enter image description here

Here's web.config: enter image description here

And here's my code:

var message = new MailMessage {     From = new MailAddress(fromAddress, fromFriendly),     Sender = new MailAddress(fromAddress, fromFriendly),     Body = messageBody,     Subject = subject,     IsBodyHtml = true };    

UPDATE: I moved my code to a different server, and it started working. Turns out my code was fine

(ノಠ益ಠ)ノ彡┻━┻ So what would cause this to happen??

3 Answers

Answers 1

Assuming information is being correctly retrieved from your configuration file, this works with no need for any additional settings:

    protected void Page_Load(object sender, EventArgs e)     {         var message = new MailMessage         {             From = new MailAddress(fromAddress, "Friendly Name"),             Subject = "Test Friendly Name",             Body = "Friendly name works !"         };          message.To.Add(recipient);          var client = new SmtpClient         {             Host = "smtp.gmail.com",             Port = 587,             EnableSsl = true,             UseDefaultCredentials = false,             Credentials = new NetworkCredential             {                 UserName = username,                 Password = password             }         };          client.Send(message);     } 

enter image description here


EDIT: I just tried the very same code using account / host information from our domain and it works just as good:

enter image description here

Answers 2

Use the overload constructor of the MailAddress like you have in your code.

I would remove the Friendly Name specified in the Configuration. The configuration setting should just have the Email Address listed.

UPDATE:

I wrote a sample code with the exact same settings and sent email through our internal mail relay. The email was sent fine and did display the friendly name in the sent email.

The one thing I would check is any network policy if any is in place within your network to trim the friendly name display while sending mail internally/externally.

Answers 3

You could try an encoded markup in your from attribute.

<smtp deliveryMethod="Network" from="Friendly Displayname &lt;your.mail@domain.com&gt;"> 

I know this still does not explain why it works on another server without this format.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment