我正在使用此 C# 代码生成一个字符串形式的 Html 表,其中包含两个超链接按钮“批准”和“拒绝”。一切正常,我使用我们的发送邮件代码在 Outlook 中收到了邮件,其中有两个按钮“批准”和“拒绝”。
现在我们面临的问题是,当您单击包含正文部分的“批准”按钮时,该正文部分再次位于 HTML 表格中,但不幸的是,它生成的正文是 HTML 表格部分作为纯文本字符串,而不是如下预期的 HTML 表格
<b>Mobile Network Information System(MNIS) Activity Assignment Notification:</b> <br>
<table style='background-color: aliceblue; border-right: gray thin groove; border-top: gray thin groove; border-left: gray thin groove; border-bottom: gray thin groove;'>
<tr>
<td colspan='2'><span>Following activity requires action from your Group :- NE Planning Managers User -36511</span></td>
</tr>
<tr>
<td>Proj Ref No</td>
<td >1052460</td>
</tr>
<tr >
<td > Region</td>
<td > NE</td>
</tr>
<tr>
<td>Type</td>
<td > MNIS New Site Development</td>
</tr>
<tr>
<td>Description</td>
<td style='font-weight: bold'>MNIS New Site Development-[1052460]-N-PUBLIC LAND-900(EM_NW_900_TestSite)</td>
</tr>
<tr >
<td > Activity</td>
<td style='font-weight: bold'>Approve RNS Final</td>
</tr>
<tr>
<td>ECD</td>
<td > </td>
</tr>
<tr>
<td>Assigned Date</td>
<td > 31/10/2024</td>
</tr>
<tr>
<td>Performer Comments(Previous)</td>
<td > </td>
</tr>
------Please type your Performer Comments above---------
Note: You can also add attachments to the task by attaching them to this email.-----Do not edit below this line-----Approve: 1052460
</table>
这是用于生成的 C# 代码:
table = new StringBuilder();
{
table.Append("<b>" + GetApplicationNameById(dr["APPLICATION_ID"].ToString()) + "(" + dr["APPLICATION_ID"].ToString() + ") Activity Assignment Notification:</b> <br>")
.Append("<table style='background-color: aliceblue; border-right: gray thin groove; border-top: gray thin groove; border-left: gray thin groove; border-bottom: gray thin groove;'> ")
.Append("<tr>")
.Append("<td colspan='2'>")
.Append("<span>Following activity requires action from your ")
.Append("Group :- " + dr["GROUP_NAME"].ToString() + " User " + dr["PF_NUMBER"].ToString() + "</span></td>")
.Append("</tr>")
.Append("<tr>")
.Append("<td>")
.Append("Proj Ref No</td>")
.Append("<td >" + dr["PROJECT_SLNO"].ToString() + "</td>")
.Append("</tr> <tr >")
.Append("<td > Region</td> ")
.Append("<td > " + dr["REGION_CODE"].ToString() + "</td>")
.Append("</tr> <tr> <td>Type</td> ")
.Append("<td > " + dr["PROJECT_TYPE_NAME"].ToString() + "</td></tr> ")
.Append("<tr> <td>Description</td><td style='font-weight: bold'>" + dr["PROJ_DESC"].ToString() + "</td>")
.Append("</tr><tr > <td > Activity</td><td style='font-weight: bold'>" + dr["ACTION_NAME"].ToString() + "</td></tr>")
.Append("<tr><td>ECD</td>")
.Append("<td > " + dr["FINAL_ECD"].ToString() + "</td> </tr>")
.Append("<tr><td>Assigned Date</td>")
.Append("<td > " + dr["ASSIGNED_DATE"].ToString() + "</td> </tr>")
.Append("<tr><td>Performer Comments(Previous)</td>")
.Append("<td > " + previous_section_comments.ToString() + "</td> </tr>")
.Append("<tr><td><a href=\"mailto:[email protected]?subject=Approve:%20" + dr["PROJECT_SLNO"].ToString() + "%20" + dr["ACTION_SUB_NO"].ToString() + "\">Approve</a></td>")
.Append("<td><a href=\"mailto:[email protected]?subject=Reject:%20" + dr["PROJECT_SLNO"].ToString() + "%20" + dr["ACTION_SUB_NO"].ToString() + "\">Reject</a></td> </tr></table>");
}
StringBuilder bodyContent = new StringBuilder();
bodyContent.Append(table.ToString().Substring(0, table.ToString().LastIndexOf("<tr><td><a href"))); // Excludes the last row with Approve/Reject
// Additional body text
string additionalText = "\n------Please type your Performer Comments above---------\n" +
"Note: You can also add attachments to the task by attaching them to this email.\n" +
"-----Do not edit below this line-----\n";
// Generate mailto body for Approve and Reject
string approveBody = bodyContent.ToString() + additionalText + "Approve: " + dr["PROJECT_SLNO"].ToString() + "</table>";
string rejectBody = bodyContent.ToString() + additionalText + "Reject: " + dr["PROJECT_SLNO"].ToString() + "</table>";
string urlEncodedApproveBody = approveBody;
string urlEncodedRejectBody = rejectBody;
// Append the body content to the mailto links
string approveLink = "<a href=\"mailto:[email protected]?subject=Approve:%20" + dr["PROJECT_SLNO"] + "%20" + dr["ACTION_SUB_NO"] + "&body="+urlEncodedApproveBody+"\">Approve</a>";
string rejectLink = "<a href=\"mailto:[email protected]?subject=Reject:%20" + dr["PROJECT_SLNO"] + "%20" + dr["ACTION_SUB_NO"] + "&body="+urlEncodedRejectBody+"\">Reject</a>";
// Replace the old Approve/Reject row with the new one containing the links
table.Replace(
table.ToString().Substring(table.ToString().LastIndexOf("<tr><td><a href")), // Find the original Approve/Reject row
"<tr><td>"+approveLink+"</td><td>"+rejectLink+"</td></tr></table>" // New row with updated links
);
// .Append("<a href='" + AppServer + "branch=" + dr["REGION_CODE"] + "&userid=" + dr["USERID"].ToString() + "&sid="+Global.EncryptPassword(GetPasswordByUserId(dr["USERID"].ToString()))+"&PROJECT_SLNO=" + dr["PROJECT_SLNO"] + "&ACTION_SUB_NO=" + dr["ACTION_SUB_NO"].ToString() + "&from=mail&projecttype=" + dr["PROJECT_TYPE"].ToString() + "'>" + " Click here for details </a>");
MailText = table.ToString();
不确定这是否是您正在寻找的...
每当我使用我使用的方法创建代码来创建和发送电子邮件时,通常都会有一个 .HTMLBody 属性来添加 html,而不是将其添加到 .Body