C# 使用mailto和windows窗体添加表

C# 使用mailto和windows窗体添加表,c#,winforms,outlook,C#,Winforms,Outlook,我想打开邮件,然后在邮件正文中创建一个表,并在模型中插入值。因此,我执行outlook时如下所示: var mail = $"mailto:test@test.com?subject=ProjectListTest&body={finalString}"; 我的问题是,如何创建一个表并添加到mailto的主体中 表标题:名称、客户 因此,在每一行中,我想使用如下内容: var finalString = string.Empty; foreach(var customer in Cu

我想打开邮件,然后在邮件正文中创建一个表,并在模型中插入值。因此,我执行outlook时如下所示:

 var mail = $"mailto:test@test.com?subject=ProjectListTest&body={finalString}";
我的问题是,如何创建一个表并添加到mailto的主体中

表标题:名称、客户

因此,在每一行中,我想使用如下内容:

var finalString = string.Empty;
foreach(var customer in CustomerList)
 {
      finalString = finalString + customer.Name + customer.CustomerKey
 }

有可能做到这一点吗?在Outlook中创建表的正确格式是什么。关于

如果表格将使用html邮件正文格式创建,则可以使用以下方法生成:

public string GenerateMailBodyWithTable(List<Customer> customers)
{
    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.Append($"<html>{ Environment.NewLine }<body>{ Environment.NewLine }");

    if (customers.Count > 0)
    {
        stringBuilder.Append($"<table><tr><th>Name</th><th>Key</th></tr>{ Environment.NewLine }");

        foreach (Customer customer in customers)
        {
            stringBuilder.Append($"<tr><th>{ customer._name }</th><th>{ customer._key }</th></tr>{ Environment.NewLine }");
        }

        stringBuilder.Append($"<table>{ Environment.NewLine }");
    }
    else
    {
        stringBuilder.Append($"<p>No customers<p>{ Environment.NewLine }");
    }

    stringBuilder.Append($"</html>{ Environment.NewLine }</body>");

    return stringBuilder.ToString();
}
不要忘记使用以下语句:

using Outlook = Microsoft.Office.Interop.Outlook;

首先,您必须创建自定义HTML:

string finalString = "<table><tr><td><b>Name</b></td><td><b>Customer</b></td></tr>";
foreach(var customer in CustomerList)
{
    finalString += "<tr><td>" + customer.Name + "</td><td>" + customer.CustomerKey + "</td></tr>";
}
finalString += "</table>";
如果要模拟“mailto”操作,可以使用:

string command = $"mailto:test@test.com?subject=ProjectListTest&body={finalString}";  
Process.Start(command); 

关于

您打算将表附加到邮件正文的末尾,还是应该将其放置在邮件正文中的特定位置?我只是想将其添加到正文中,我不关心position@iliassnassibane,我尝试按照您的建议将其与mailto一起使用,但它只是将html代码打印到outlook正文中,而不是创建我不理解的表格。如果您使用Outlook阅读电子邮件,是否会显示HTML代码而不是表格?您是否尝试将电子邮件发送到其他邮箱?Gmail?结果是一样的?我试过了,但它只是在outlook正文中打印html代码,我认为outlook使用了另一种格式,它们不使用htmlbody@Ruben,我已经编辑了我的答案,以完成您电子邮件的HTML正文的填写。
MailMessage mail = new MailMessage("from", "mailto", "Subject", finalString);
mail.IsBodyHtml = true; //Important
SmtpClient smtp = new SmtpClient("serverSMTP");
smtp.EnableSsl = USE_SSL;
smtp.Port = YOUR_PORT;
smtp.Credentials = new System.Net.NetworkCredential("email", "password");
smtp.Send(correo);
string command = $"mailto:test@test.com?subject=ProjectListTest&body={finalString}";  
Process.Start(command);