在过去,我已经使用类似这样的形式发送表单字段的电子邮件形式的asp.net,我想格式更多的HTML电子邮件,但我没有知道如何将文本框的值传递给消息可以有人帮助我吗?如何在电子邮件正文ASP.NET中添加表单文本
//OLD WAY
message.Body += "<b>Preferred contact method: </b> " + drp_contact_method.SelectedValue + "<br/>";//
protected void btnAction_Click(object sender, EventArgs e)
{
if ((Page.IsValid))
{
if (dpAction.SelectedValue.ToString()=="Submit")
{
// define SMTP client
SmtpClient smtp = new SmtpClient("IP HERE");
//smtp.EnableSsl = true;
// smtp.UseDefaultCredentials = true;
//create the mail message
MailMessage message = new MailMessage();
//From address will be given as a MailAddress Object
message.From = new MailAddress("[email protected]");
//To address collection of MailAddress
message.To.Add("[email protected]");
message.Subject = "Pre-Registration Form";
// Change to false to not include HTML
string bodyHTML = string.Empty;
string bodyPlain = string.Empty;
message.IsBodyHtml = true;
bodyHTML = @"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
'http://www.w3.org/TR/html4/loose.dtd'>
<html lang='en'>
<head>
</head>
<body>
<table style='width:800px; border:1px solid #000;' cellpadding='10' cellspacing='0' align='center'>
<tr>
<td colspan='2' style='background-color:#009797; border-bottom:1px solid #000;'>
<h1 style='text-align:center; color:#FFF;'>Pre-Registration Information</h1></td>
</tr>
<td style='width:600px; vertical-align:top;'>
<h4 style='font-family:Arial, Helvetica, sans-serif; color:#000;'><u>PATIENT INFORMATION</u></h4>
<p style='font-family:Arial, Helvetica, sans-serif; font-size:.8em; color:#000; line-height:1.5em;'>Last Name:</p>
+ txtLastName.Text +
通常,您不会像这样在类文件中写出您的html,您可以创建用户控件并将业务逻辑放在用户控件代码后面。然后,在您的电子邮件发送类/方法中,您可以执行用户控件,方法与通过将控件放在页面上执行相同的方式执行,除非您可以取回将最终发送到客户端的html字符串。 – 2011-12-21 00:41:50