Sam
Sam

Reputation: 4484

How to add a display name to mail sent via SMTP

I am sending mail via gmail SMTP account by adding below in Global.asax file -

WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
WebMail.UserName = "[email protected]";
WebMail.From = "[email protected]";
WebMail.Password = "nopassword";
WebMail.SmtpUseDefaultCredentials = false;

When I send a mail through WebMail.Send() method, the mail is sent properly, but the recieved mail always has name - "accname". What I want it to show it as some other name - let's say "Name". How should I do that here?

Upvotes: 6

Views: 23804

Answers (2)

Dojo Arun
Dojo Arun

Reputation: 419

If you are using appsettings.json, you have to give the Email Configuration like this:

"EmailConfiguration" : {
    "SmtpServer": "smtp.gmail.com",
    "SmtpPort": 587,
    "UserName": "[email protected]",
    "From": "Name To Display<[email protected]>",
    "Password": "nopassword",
    "EnableSsl": true
}

Upvotes: 0

DavidG
DavidG

Reputation: 119146

You can set the From property to include the name as well as the email address:

WebMail.From = "Your Name <[email protected]>";

You may need to surround the name with quotes, for example:

WebMail.From = "\"Your Name\" <[email protected]>";

Upvotes: 14

Related Questions