需要替换电子邮件正文模板中的超链接 html
need to replace hyperlinks in email body template html
我有一个电子邮件正文模板,用于向客户发送包含运输跟踪编号和跟踪站点链接的电子邮件。
逻辑使我能够使用此模板来包含最多 5 个跟踪编号和链接。如果客户只有 2 个跟踪号,逻辑应该删除其他三个字段。
html 电子邮件正文模板:
<body>
Dear [FIRSTNAME]{LAST NAME},
Your package was shipped via USPS using tracking # [TRACKINGNUMBER1], [TRACKINGNUMBER2], [TRACKINGNUMBER3], [TRACKINGNUMBER4], [TRACKINGNUMBER5]
Track your package(s) : <a href="https://xUSPSx//[TRACKINGNUMBER1]">Click Here (#1)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER2]">Click Here (#2)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER3]">Click Here (#3)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER4]">Click Here (#4)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER5]">Click Here (#5)</a>
Thank You.
</body>
控制器逻辑:
If(orderinfo.shipmethod=="FedEx")
{
emailtemplate=emailtemplate.replace("Your package was shipped via USPS","Your package was shipped via FedEx");
emailtemplate=emailtemplate.replace("https://xUSPSx//","https://xFEDEXx//");
}
string trackingnos[]=// receives all tracking nos
int arraylength=trackingnos.length;
for(int i=0; i<arraylength;i++)
{
emailtemplate=emailtemplate.replace("[TRACKINGNUMBER" + (i+1) + "], trackingnos[i]);
}
for(;arraylength<=5; arraylength++)
{
emailtemplate=emailtemplate.replace(", [TRACKINGNUMBER" + (i+1) + "], "");
emailtemplate=emailtemplate.replace(", Click Here (#" + arraylength + ")", "" );
}
以下控制器逻辑可用于替换跟踪编号,但仍未替换空白字段的超链接。
你能建议我的逻辑更正吗
如果要替换所有内容,为什么要使用模板?为什么不从头开始构建它?
这就是我在根据您的情况调整的程序中的做法。
private void SendEmail() //parameters if needed Client client, OrderInfo orderinfo
{
string trackingnos[] = ;// receives all tracking nos
int arraylength = trackingnos.length;
StringBuilder emailtemplate = new StringBuilder();
emailtemplate.Append("<body> Dear " + client.FIRSTNAME + " " + client.LastNAME + ", <br/>");
emailtemplate.Append("Your package was shipped via " + orderinfo.shipmethod + "using tracking # ");
for (int i = 0; i < arraylength; i++)
{
if (i != arraylength - 1)
{
emailtemplate.Append(trackingnos[i] + ", ");
}
else
{
emailtemplate.Append(trackingnos[i] + ", <br/>");
}
}
emailtemplate.Append("Track your package(s) : <br/>");
for (int i = 0; i < arraylength; i++)
{
emailtemplate.Append("<a href=\"https://x"+orderinfo.shipmethod+"x//" + trackingnos[i] +"\">Click Here (#"+i+")</a> <br/>");
}
emailtemplate.Append("Thank you. <br/> </body> ");
Microsoft.Office.Interop.Outlook.MailItem eMail = OutlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
eMail.Subject = "Package shipped";
eMail.To = client.Email;
eMail.HTMLBody = emailtemplate.ToString();
eMail.Send();
}
我有一个电子邮件正文模板,用于向客户发送包含运输跟踪编号和跟踪站点链接的电子邮件。
逻辑使我能够使用此模板来包含最多 5 个跟踪编号和链接。如果客户只有 2 个跟踪号,逻辑应该删除其他三个字段。
html 电子邮件正文模板:
<body>
Dear [FIRSTNAME]{LAST NAME},
Your package was shipped via USPS using tracking # [TRACKINGNUMBER1], [TRACKINGNUMBER2], [TRACKINGNUMBER3], [TRACKINGNUMBER4], [TRACKINGNUMBER5]
Track your package(s) : <a href="https://xUSPSx//[TRACKINGNUMBER1]">Click Here (#1)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER2]">Click Here (#2)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER3]">Click Here (#3)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER4]">Click Here (#4)</a>,
<a href="https://xUSPSx//[TRACKINGNUMBER5]">Click Here (#5)</a>
Thank You.
</body>
控制器逻辑:
If(orderinfo.shipmethod=="FedEx")
{
emailtemplate=emailtemplate.replace("Your package was shipped via USPS","Your package was shipped via FedEx");
emailtemplate=emailtemplate.replace("https://xUSPSx//","https://xFEDEXx//");
}
string trackingnos[]=// receives all tracking nos
int arraylength=trackingnos.length;
for(int i=0; i<arraylength;i++)
{
emailtemplate=emailtemplate.replace("[TRACKINGNUMBER" + (i+1) + "], trackingnos[i]);
}
for(;arraylength<=5; arraylength++)
{
emailtemplate=emailtemplate.replace(", [TRACKINGNUMBER" + (i+1) + "], "");
emailtemplate=emailtemplate.replace(", Click Here (#" + arraylength + ")", "" );
}
以下控制器逻辑可用于替换跟踪编号,但仍未替换空白字段的超链接。 你能建议我的逻辑更正吗
如果要替换所有内容,为什么要使用模板?为什么不从头开始构建它?
这就是我在根据您的情况调整的程序中的做法。
private void SendEmail() //parameters if needed Client client, OrderInfo orderinfo
{
string trackingnos[] = ;// receives all tracking nos
int arraylength = trackingnos.length;
StringBuilder emailtemplate = new StringBuilder();
emailtemplate.Append("<body> Dear " + client.FIRSTNAME + " " + client.LastNAME + ", <br/>");
emailtemplate.Append("Your package was shipped via " + orderinfo.shipmethod + "using tracking # ");
for (int i = 0; i < arraylength; i++)
{
if (i != arraylength - 1)
{
emailtemplate.Append(trackingnos[i] + ", ");
}
else
{
emailtemplate.Append(trackingnos[i] + ", <br/>");
}
}
emailtemplate.Append("Track your package(s) : <br/>");
for (int i = 0; i < arraylength; i++)
{
emailtemplate.Append("<a href=\"https://x"+orderinfo.shipmethod+"x//" + trackingnos[i] +"\">Click Here (#"+i+")</a> <br/>");
}
emailtemplate.Append("Thank you. <br/> </body> ");
Microsoft.Office.Interop.Outlook.MailItem eMail = OutlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
eMail.Subject = "Package shipped";
eMail.To = client.Email;
eMail.HTMLBody = emailtemplate.ToString();
eMail.Send();
}