5

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 = "accname@example.com";
WebMail.From = "accname@example.com";
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?

Sam
  • 4,302
  • 12
  • 40
  • 74

2 Answers2

12

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

WebMail.From = "Your Name <accname@example.com>";

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

WebMail.From = "\"Your Name\" <accname@example.com>";
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • 1
    It throws this exception - The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. – Sam Feb 17 '15 at 17:16
  • 1
    I think that is the actual account id as per WebMail class documentation. – Sam Feb 17 '15 at 17:17
  • This is working fine. I did not require to quote the name. Thanks. But this seems like a hack. Do you know if this will work even if gmail is not the mail server? – Sam Feb 17 '15 at 17:29
0

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

"EmailConfiguration" : {
    "SmtpServer": "smtp.gmail.com",
    "SmtpPort": 587,
    "UserName": "accname@example.com",
    "From": "Name To Display<accname@example.com>",
    "Password": "nopassword",
    "EnableSsl": true
}
Luke
  • 743
  • 6
  • 20
Dojo Arun
  • 21
  • 2