예전에 전자 메일 양식 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 문자열을 다시 얻을 수 있다는 점만 다릅니다. –