3

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?

4

1 回答 1

3

DisplayNameMailAddress类的属性。您可以使用构造函数的此重载来指定它:

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

根据评论更新:

DisplayName属性没有(或私有的)setter,这意味着您只能通过 的构造函数来设置它MailAddress,而不能通过属性本身进行设置。

于 2013-10-09T18:11:19.287 回答