2010-09-22 83 views
3

我正在嘗試使用姓名和電子郵件地址更改FROM字段。但是,當我收到的電子郵件,其如下如何更改電子郵件地址字段?

My network <[email protected] [My network <[email protected]] 

mycode的顯示是像下面

const string from = "My network <[email protected]>"; 

    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 + ""); 

我想從電子郵件地址應該showup像下面

My network [[email protected]] 

回答

3

SPUtility.SendMail將始終使用管理中心>外發電子郵件設置中指定的來自smtp地址,並且友好名稱將設置爲該網站的標題。

相反,你可以使用(從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("[email protected]", "Steve James"); 
mail.To.Add("[email protected]"); 

//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); 
1

我相信,如果你看看在.Net框架的郵件對象中,你可以做你想做的事情。

Maybe this site可以幫助你進一步?

2

我知道這個線程是舊的,但如果有人遇到這個像我一樣,你原來的代碼會使用SPUtility.SendMail如果你工作得很好友好名稱周圍的附加引號如下所示:

const string from = "\"My network\" <[email protected]>";