C# Webmail.Send method how to change person name
Question
WebMail.SmtpServer = SmtpServer;
WebMail.UserName = SmtpUsername;
WebMail.Password = SmtpPassword;
WebMail.Send(
ReplayEmail,
subject,
body,
email
);
subject is for example "Ask specialist"
body is html body
email is for example "domain@domain.com"
email is send to for example "domain2@domain.com"
now when i send mail i get mail which is ok but as person who send mail I see "domain2@domain.com". how to change this?
mail now looks like
domain2@domain.com Ask specialist
i want name (Adoo for example) and mail like
Adoo Ask specialist
Solution
If I understand correctly, when setting up mail you can do :
mail.To = new MailAddress("domain2@domain.com", "Adoo");
or :
mail.To= @"\Adoo \ <domain2@domain.com>";
OTHER TIPS
I'm assuming ReplayAddress
is a System.Net.Mail.MailAddress
defined in code somewhere else you haven't shown. MailAddress has a constructor which takes a string displayName
which should do what you want if I understand you correctly - documentation on that is here.
Typically in SMTP you can create a friendly name by using a format like this:
WebMail.Send(
"\"Adoo\" <domain2@domain.com>",
subject,
body,
email
);
or you can use
mail.To= @""Adoo" <domain2@domain.com>";
You are using the WebMail class which takes a string for the .From property of the class. I would use the MailAddress class and do:
MailAddress from = new MailAddress("domain2@domain.com", "Adoo Ask specialist");