Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Windows 8 metro中以html格式发送电子邮件_C#_Html_Email_Microsoft Metro - Fatal编程技术网

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

C# 在Windows 8 metro中以html格式发送电子邮件,c#,html,email,microsoft-metro,C#,Html,Email,Microsoft Metro,我正在编写一个数据密集型的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); 这对

我正在编写一个数据密集型的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>";
string htmlString=“”
DALClient client=新的DALClient();
htmlString+=“”;
htmlString+=“”;
List people=client.getPeopleWithReservations();
foreach(人员ppl以人员为单位)
{
htmlString+=“”
htmlString+=“”+ppl.PersonName+“”;
htmlString+=“”;
}
htmlString+=“”;
htmlString+=“”;
现在,当我运行此代码时,电子邮件客户端将打开。但是,结果显示为纯文本。有没有一种方法可以让它显示在格式化的html中,这样html标签等就不会显示了?
提前感谢。

无法将HTML传递给mailto。您可以使用共享,将HTML代码传递给默认的Windows应用商店邮件应用程序(很遗憾,不是默认的桌面邮件应用程序)

以下是页面上的示例:

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(); 
公共密封部分类主页面:第页
{
私有字符串主题;
私有字符串eMailHtmlText;
...
私有void OnDataRequested(DataTransferManager发送方,DataRequestedEventArgs参数)
{
//检查是否有用于共享的电子邮件
if(String.IsNullOrEmpty(this.eMailHtmlText)==false)
{
//通过当前科目
args.Request.Data.Properties.Title=this.eMailSubject;
//传递当前电子邮件文本
args.Request.Data.SetHtmlFormat(
创建htmlformatter(this.eMailHtmlText));
//删除当前主题和文本以避免多次共享
this.eMailSubject=null;
this.eMailHtmlText=null;
}
其他的
{
//传递一个文本,该文本报告当前不存在用于共享的内容
args.Request.FailWithDisplayText(“当前没有用于共享的电子邮件”);
}
}
...
//“发送”电子邮件
this.eMailSubject=“Test”;
this.eMailHtmlText=“嘿,

”+ “这只是一个测试。”; DataTransferManager.ShowShareUI();
另一种方法是使用SMTP,但据我所知,Windows应用商店应用程序尚未实现SMTP