2013-03-11 85 views
0

我正在寫一個非常密集的Metro應用程序,我需要以html格式發送電子郵件。經過Google搜索後,我看到了這段代碼。在Windows 8中以html格式發送電子郵件metro

​​

這對我來說很好,但有一個例外。我通過html字符串生成這封電子郵件的正文,所以我在我的班級中有這樣的代碼。

string htmlString="" 
DALClient client = new DALClient(); 
htmlString += "<html><body>"; 
htmlString += "<table>"; 
List<People> people = client.getPeopleWithReservations(); 
foreach(People ppl in people) 
{ 
    htmlString+="<tr>" 
    htmlString +="<td>" + ppl.PersonName + "</td>"; 
    htmlString +="</tr>"; 
} 
htmlString +="</table>"; 
htmlString +="</body><html>"; 

現在,當我運行此代碼的電子郵件客戶端打開。但結果顯示爲純文本。有沒有一種方法,我可以在格式化的HTML顯示,所以HTML標籤等不會顯示? 在此先感謝。

回答

1

這是不可能的HTML傳遞給mailto。您可以使用共享來代替將HTML代碼傳遞到默認Windows Store郵件應用程序的位置(不幸的是不會默認使用默認的桌面郵件應用程序)。

這裏是一個頁面上的樣本:

public sealed partial class MainPage : Page 
{ 
    private string eMailSubject; 
    private string eMailHtmlText; 

    ... 

    private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args) 
    { 
     // Check if an email is there for sharing 
     if (String.IsNullOrEmpty(this.eMailHtmlText) == false) 
     { 
     // Pass the current subject 
     args.Request.Data.Properties.Title = this.eMailSubject; 

     // Pass the current email text 
     args.Request.Data.SetHtmlFormat(
      HtmlFormatHelper.CreateHtmlFormat(this.eMailHtmlText)); 

     // Delete the current subject and text to avoid multiple sharing 
     this.eMailSubject = null; 
     this.eMailHtmlText = null; 
     } 
     else 
     { 
     // Pass a text that reports nothing currently exists for sharing 
     args.Request.FailWithDisplayText("Currently there is no email for sharing"); 
     } 
    } 

    ... 

    // "Send" an email 
    this.eMailSubject = "Test"; 
    this.eMailHtmlText = "Hey,<br/><br/> " + 
     "This is just a <b>test</b>."; 
    DataTransferManager.ShowShareUI(); 

另一種方法是使用SMTP,但據我所知是沒有SMTP實現卻爲Windows應用商店的應用程序。