在Windows 8 metro中以html格式发送电子邮件

本文关键字:格式 电子邮件 html 中以 Windows metro | 更新日期: 2023-09-27 18:03:23

我正在编写一个非常数据密集的Metro应用程序,我需要以html格式发送电子邮件。在谷歌搜索之后,我发现了这段代码。

var mailto = new Uri("mailto:?to=recipient@example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.");
await Windows.System.Launcher.LaunchUriAsync(mailto);

这对我来说非常有效,只有一个例外。我通过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标签等就不会显示了?

在Windows 8 metro中以html格式发送电子邮件

不可能将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,但据我所知,Windows Store应用程序还没有SMTP实现。