Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

email

iis

smtp

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

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??

like image 735
codeMonkey Avatar asked Jun 14 '17 00:06

codeMonkey


1 Answers

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

like image 176
jsanalytics Avatar answered Sep 21 '22 18:09

jsanalytics