将字符串转换为电子邮件中的链接

时间:2016-08-01 18:59:33

标签: c# asp.net email hyperlink web-config

我正在尝试在创建工单时向主管发送电子邮件

    if(TextBox9.Text=="Quality"&&affectedrows==true)
    {
    boolisLocal=HttpContext.Current.Request.IsLocal;
    if(isLocal==true)
    {
    System.Net.Mail.MailMessagenn=newSystem.Net.Mail.MailMessage();
    nn.From=newSystem.Net.Mail.MailAddress("no_reply_workorder@mover.com");//whosend
    nn.To.Add(newSystem.Net.Mail.MailAddress("someone.something@mover.com"));

    nn.Subject="WorkOrdersTypeQuality";
    HttpFileCollectionuploadFiles=Request.Files;
    for(inti=0;i<uploadFiles.Count;i++)
    {
    HttpPostedFileuserpostedfils=uploadFiles[i];
    try
    {
    if(userpostedfils.ContentLength>0)
    {
    nn.Attachments.Add(newAttachment(userpostedfils.InputStream,Path.GetFileName(userpostedfils.FileName)));
    }
    }

    catch
    {
    Labelstatusmessage=(Label)DetailsView1.FindControl("lblmessage");
    statusmessage.Text="UploadFailedPleaseContactDeveloper";
    }
    }
    nn.Body="DONOTREPLYTOTHISEMAIL"+"<br><br/>"+"WorkOrderNumber"+":&nbsp;"+
"<ahref=\"http://localhost:49695/QualityReport.aspx?WorkOrderNum="+TextBox13.Text+"\">"+TextBox13.Text+"</a>"+"<-ClickontheWorkOrderNumberForReport"+"<br><br/>"+"WorkOrderNumber"+
":&nbsp;"+"<ahref=\"http://localhost:49695/Quality.aspx?WorkOrderNum="+TextBox13.Text+"\">"+TextBox13.Text+"</a>"+"<-ClickontheWorkOrderNumberToEnterData"+"<br><br/>"+"Requestor"+
":&nbsp;"+TextBoxRequestor.Text+"<br><br/>"+"Date"+":&nbsp;"+
TextBoxDate.Text+"<br><br/>"+"Department"+":&nbsp;"+
TextBox14.Text+"<br><br/>"+"CompletionDate"+":&nbsp;"+
TextBoxCompletionDate.Text+"<br><br/>"+"MachineDescription"+
":&nbsp;"+TextBoxMachineDescription.Text+"<br><br/>"+
"MachineLocation"+":&nbsp;"+TextBoxMachineLocation.Text+
"<br><br/>"+"WorkRequired"+":&nbsp;"+TextBoxWorkRequired.Text+
"<br><br/>"+"Status"+":&nbsp;"+TextBoxStatus.Text;
    nn.IsBodyHtml=true;
    System.Net.Mail.SmtpClientclient=newSystem.Net.Mail.SmtpClient();
    client.Host=ConfigurationManager.AppSettings["smtpServer"];
    captureuseremail();
    }
    }

在邮件正文中我发送了刚刚创建的工作订单的链接,“http://server01/WorkOrder/QualityReport.aspx?WorkOrderNum =”TextBox13.Text +“\”&gt;“我正在工作在四个不同的工厂,所以我需要将每个项目部署到4个服务器并将上面的链接更改为server02,server03和server04,并且有3种类型的工作器,所以我想将每个链接存储到web.config中的一个键中: / p>

 <add key ="safetylink" value="http://server01/WorkOrderTool/SafetyReport.aspx?WorkOrderNum="/>

从web.config获取值并以字符串形式存储并在电子邮件中使用它我不知道该怎么做:

 string safetylink = ConfigurationManager.AppSettings["safetylink"];
 mm.Body = "DO NOT REPLY TO THIS EMAIL" + "<br><br/>" + "WorkOrderNumber" + ": &nbsp;" + "<a href=\"safetylink" + TextBox13.Text + "\">"

但这不起作用,通过执行上述操作,我希望将一个Web应用程序简单地部署到4个服务器并进入每个web.config并更改服务器的名称而不是查找和替换。

提前感谢编码员

1 个答案:

答案 0 :(得分:1)

感谢SamIam,只要您想在电子邮件正文中发送字符串作为超链接:

use "<a href=\"" + yourstringname"