开发者

How to change email FROM address field?

I was trying to chang开发者_运维百科e FROM field with Name and Email address. But When I receive the email, Its shown as below

My network <commity@company.com [My network <commity@company.com]

Mycode is like below

    const string from = "My network <commity@company.com>";

    StringDictionary headers = new StringDictionary();
       headers.Add("to", invitee.userEmail);
       headers.Add("subject", ltEmailSubject.Text);
       headers.Add("from", from);
       headers.Add("content-type", MediaTypeNames.Text.Html);

       _emailSuccessful = SPUtility.SendEmail(elevatedSite.RootWeb, headers,
                          emailBody + Environment.NewLine + "");

I want FROM email address should showup like below

My network [commity@company.com]


SPUtility.SendMail will always use the from smtp address as specified in Central Administration > Outgoing Email Settings and the friendly name is set to the title of the site.

Instead you can use (from http://www.systemnetmail.com/faq/3.2.1.aspx)

MailMessage mail = new MailMessage();

//set the addresses
//to specify a friendly 'from' name, we use a different ctor
mail.From = new MailAddress("me@mycompany.com", "Steve James" );
mail.To.Add("you@yourcompany.com");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);


I know this thread is old, but in case someone comes across this as I did, your original code would have worked fine using SPUtility.SendMail if you added quotes around the friendly name in the from address like this:

const string from = "\"My network\" <commity@company.com>";


I believe if you look at the mail object in the .Net Framework, you could do what you wish to do.

Maybe this site could help you out further?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜