Need to change FromEmail String when sending Email through SMTPClient
-
22-07-2019 - |
Question
My Email Sending Code
MailMessage msg = new MailMessage("mailer@abc.com", "xyz@hotmail.com", "testing email", "to check from email label text");
SmtpClient smpt = new SmtpClient();
smpt.Send(msg);
When email open by xyz@hotmail.com user, In the from email, its mentioned mailer@abc.com where as I need to show like Abc Corporation [abc@nextech.pk]
How can I change from Email address label
Thanks
Solution
Create a MailAddress with the real name and email address, then supply that to the MailMessage.
From MSDN (From property for MailMessage).
MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
OTHER TIPS
Use the DisplayName
MailMessage m = new MailMessage();
m.From = new MailAddress("mail@mailserver.com", "My Mail");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow