purpose of life is joy

NAVIGATION - SEARCH

Tips : Sending emails with custom name instead of sender email in asp.net

While sending mails using system.net from asp.net, mail inbox always shows as username@domainname.com. This may not looks good and also not user-friendly to the users.

One of the ways generally recommends is to pass it as parameter in MailAddress constructor class like MailAddress(email address,display name)

MailAddress mailAddress = new MailAddress("admin@balavanchi.com", "Bala Vanchi");

but it may not work other than outlook or Eudora.

To show the user-friendly names in the inbox, use the below pattern to display the custom user-friendly names.

MailAddress mailAddress = new MailAddress("admin@balavanchi.com",  "\"Bala Vanchi\" <admin@balavanchi.com>");

or

mail.From = "\"Bala Vanchi\" <admin@balavanchi.com>"

Sample C# code snippet below 

MailMessage mail = new MailMessage();
mail.To = "yourname@yourdomain.com";
mail.From = "\"Bala Vanchi\" <admin@balavanchi.com>";
mail.Subject = "User-Friendly Name test";
mail.Body = "Now name appears in the FROM section should be an user-friendly one";
SmtpMail.SmtpServer = "smtp.domain.com";
SmtpMail.Send( mail );
blog comments powered by Disqus
Protected by Copyscape Web Plagiarism Check
DMCA.com