Question

I looking to change the display name in a Email using MVCMailer. Instead of the client seeing From: custmerservice@xyzCompany.com they will see "xyzCompany Customer Service". I have looked all around the internet and can not find any documentation that explains how.

USERMAILER.CS

public virtual MvcMailMessage Welcome(string sentTo, string replyTo)
        {

            return Populate(x =>
            {
                x.Subject = "Welcome";
                x.ViewName = "Welcome"; //View name of email going out.
                x.ReplyToList.Clear();
                x.ReplyToList.Add(replyTo);
                x.To.Add(sentTo);
                x.From.DisplayName("xyz Company Customer Service"); 
                x.From = new MailAddress("customerservice@xyzCompany.com");
                x.ViewName = "WelcomeEmail"; //View name of email going out.
            });
         }

The line 'x.From.DisplayName("xyz Company Customer Service")' gives me an error: system.net.mail.mailaddress.DisplayName can not be used as a method.

Can anyone please tell me how to properly change the displayname?

Was it helpful?

Solution

DisplayName is a property of the MailAddress class. You can use this overload of the constructor to specify it:

x.From = new MailAddress(address: "customerservice@xyzCompany.com", displayName: "xyz Company Customer Service");

Update based on comment:

The DisplayName property has no (or a private) setter, meaning you can only set it through the constructor of MailAddress, but not through the property itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top