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??
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);
}
EDIT: I just tried the very same code using account / host information from our domain and it works just as good:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With