C# 如何在字符串变量或文本框c中存储html代码电子邮件模板

C# 如何在字符串变量或文本框c中存储html代码电子邮件模板,c#,html,html-email,C#,Html,Html Email,在我的程序中,用户将选择模板消息,它将显示在正文文本框中。模板是HTML格式的 if(templatelistbox.SelectedItem.ToString().Equals("Order Processing")) { string m; 我想将下面的html存储为字符串 <body> <table width="580" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFF

在我的程序中,用户将选择模板消息,它将显示在正文文本框中。模板是HTML格式的

if(templatelistbox.SelectedItem.ToString().Equals("Order Processing"))
            {
string m;
我想将下面的html存储为字符串

<body>
<table width="580" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tbody>
    <tr>
      <td colspan="2" align="right" valign="middle" width="580" height="60" bgcolor="00496f"><div wotsearchtarget="flipkart.com"></div></td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="middle" width="580" bgcolor="3bb1d7"><p><strong>Order Confirmed!</strong></p></td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="top" width="580" bgcolor="ffffff"><p>&nbsp;</p>
        <p>Dear <strong>Praveen,</strong></p>
        <p>Greetings from Prostyle PC Kart</p>
        <p>We thank you for your order. This email contains your order summary. When the item(s) in your order are ready to ship, you will receive an email with the Courier Tracking ID and the link where you can track your order. You can also check the status of your order on <strong>ebay.in</strong></p>

        Please find below the summary of your order <strong> OD3</strong></a>
        at Prostyle Pc Kart Seller of eBay.in:
        </p></td>
    </tr>
    <tr>
      <td colspan="2" align="left" valign="top" width="580" bgcolor="ffffff"><table border="0" cellspacing="0" cellpadding="0" width="580">
        <tbody>
          <tr>
            <td colspan="7"><p><strong>Order ID: OD3
                |  Seller ID : eshop.prostylepc.in</strong></p>
              <p>                <strong>Item (s) Ordered:</strong></p></td>
          </tr>
          <tr>
            <td width="274" valign="top"><p><strong>Product Details</strong></p></td>

            <td width="112" valign="top"><p><strong>Shipping Date</strong></p></td>
            <td width="62" valign="top"><p><strong>Ordered Quantity</strong></p></td>
            <td width="132" valign="top"><p><center><strong>Price</strong></center></p></td>


          </tr>
          <tr>
            <td width="274" valign="top"><p>XOLO Q800</p>
              </td>
            <td width="112" valign="top"><p>&nbsp;</p></td>
            <td width="62" valign="top"><center><p>1</p></center></td>
            <td width="132" valign="top" align="center"><p>Rs. 9700</p></td>

          <tr>
            <td width="274" valign="top"><p>Samsung BHM1100NBEGINU In-the-ear Headset without Charger</p>
              </td>
            <td width="112" valign="top"><p>&nbsp;</p></td>
            <td width="62" valign="top"><center><p>1</p></center></td>
            <td width="132" valign="top" align="center"><p>Rs. 699</p></td>


          </tr>
          <tr>
            <td colspan="2"><p>Shipping Charge</p></td>
            <td width="62"><center><p>FREE</p></center></td>
          </tr>
          <tr>
            <td valign="top" colspan="3"><p><strong>Total</strong></p></td>
            <td width="132" valign="top"><p><strong>Rs. 9700</strong></p></td>
          </tr>
          <tr>
     .......................................................




bodytbox.Text = m;


            }
告诉我用c或variable插入此html代码的任何方法,或者如何通过电子邮件发送此模板。备选方案 我还需要在模板中添加一些参数。例如,用pidstatic替换的OrderNo.xxxxxx包含一些值。
提前感谢

将其保存到文件并将该文件加载到字符串中,或在应用程序设置项目->属性->设置中

string htmlCode = System.IO.File.ReadAllText("File Path");
使用应用程序设置:

string htmlCode = properties.Default.HtmlCode;

在那之后,你可以做任何你想做的事

您可以使用模板解析器


将其放入一个文件并读取该文件。它可以工作,但我需要在模板中放入一些参数。例如,ORder no替换为PaisPayidStatic。如果您有一个字符串Welcome User,并且希望在该字符串之后添加用户名,则只需执行类似于Welcome User{0}的操作即可注意{0}现在正在使用string.Format欢迎用户{0},它将用传递给它的字符串替换{0},如果有10个位置要传递值给它,只需使用{0}、{1}、{2}。。。使用string.Format和你想要的参数的个数我希望这个能帮助你