在 C# 中将正文传递给 mailto 时如何尊重空格

How to respect spaces when passing body to an mailto in C#

我有一个模板样式的页面,它构建了一个 mailto link 以在用户默认邮件客户端中打开预构建的电子邮件

我知道默认情况下使用 URLencode 会将空格替换为 +(而 pathencode 将替换为 %20 )- 但是是否可以在尊重内容中的空格的同时传递正文和主题到 mailto? - 例如,在 javascript 中使用 encodeURIComponent(yourMessage) 将保留 "yourmessage" 变量

中的空格
   private void SubmitEmail(object sender, RoutedEventArgs e)
    {
    string txt = "text that is an example";
    string rnt = "this is also an example";
    string PrioStr = "this is an example, of text that will come from a radio buttons contents";
    var yourMessage = txt;
    var subject =$"firstvariable:{Rnt}     secondvariable:{PrioStr}";

    var url =$"mailto:test@test.com.com?subject={HttpUtility.UrlEncode(subject)}&body={HttpUtility.UrlEncode(yourMessage)}"; 

     Process.Start(url);
     }

使用 Uri.EscapeDataString,这会将空格转义为 %20

private void SubmitEmail(object sender, RoutedEventArgs e)
{
    string txt = "text that is an example";
    string rnt = "this is also an example";
    string PrioStr = "this is an example, of text that will come from a radio buttons contents";
    var yourMessage = txt;
    var subject =$"firstvariable:{Rnt}     secondvariable:{PrioStr}";

    var url = $"mailto:test@test.com.com?subject={Uri.EscapeDataString(subject)}&body={Uri.EscapeDataString(yourMessage)}";
}