반응형
HTML 형식의 이메일을 보내는 방법은 무엇입니까? [복제]
이 질문에는 이미 답변이 있습니다.
- SmtpClient 6 답변으로 C #을 통해 HTML 이메일 보내기
웹 응용 프로그램이 Windows 작업 스케줄러를 사용하여 자동 전자 메일을 보내도록 할 수있었습니다. 이제 이메일을 보내기 위해 작성한 다음 방법을 사용하여 HTML 형식의 이메일을 보내려고합니다.
내 코드 숨김 :
protected void Page_Load(object sender, EventArgs e)
{
SmtpClient sc = new SmtpClient("mail address");
MailMessage msg = null;
try
{
msg = new MailMessage("xxxx@gmail.com",
"yyyy@gmail.com", "Message from PSSP System",
"This email sent by the PSSP system");
sc.Send(msg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (msg != null)
{
msg.Dispose();
}
}
}
그렇게하는 방법? 이메일에 하나의 링크와 하나의 이미지가있는 굵은 텍스트를 넣고 싶습니다.
설정 isBodyHtml
하려면 true
메시지 본문에 HTML 태그를 사용할 수 있습니다 :
msg = new MailMessage("xxxx@gmail.com",
"yyyy@gmail.com", "Message from PSSP System",
"This email sent by the PSSP system<br />" +
"<b>this is bold text!</b>");
msg.IsBodyHtml = true;
html 형식의 이메일을 보내는 가장 좋은 방법
이 코드는 " Customer.htm "에 있습니다.
<table>
<tr>
<td>
Dealer's Company Name
</td>
<td>
:
</td>
<td>
#DealerCompanyName#
</td>
</tr>
</table>
System.IO.File.ReadAllText를 사용하여 HTML 파일을 읽습니다. 모든 HTML 코드를 문자열 변수로 가져옵니다.
string Body = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("EmailTemplates/Customer.htm"));
특정 문자열을 사용자 정의 값으로 바꾸십시오.
Body = Body.Replace("#DealerCompanyName#", _lstGetDealerRoleAndContactInfoByCompanyIDResult[0].CompanyName);
call SendEmail(string Body) Function and do procedure to send email.
public static void SendEmail(string Body)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(Session["Email"].Tostring());
message.To.Add(ConfigurationSettings.AppSettings["RequesEmail"].ToString());
message.Subject = "Request from " + SessionFactory.CurrentCompany.CompanyName + " to add a new supplier";
message.IsBodyHtml = true;
message.Body = Body;
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = true;
smtpClient.Host = ConfigurationSettings.AppSettings["SMTP"].ToString();
smtpClient.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["PORT"].ToString());
smtpClient.EnableSsl = true;
smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["USERNAME"].ToString(), ConfigurationSettings.AppSettings["PASSWORD"].ToString());
smtpClient.Send(message);
}
This works for me
msg.BodyFormat = MailFormat.Html;
and then you can use html in your body
msg.Body = "<em>It's great to use HTML in mail!!</em>"
참고URL : https://stackoverflow.com/questions/8628683/how-to-send-html-formatted-email
반응형
'Programing' 카테고리의 다른 글
Vim에 파일을 저장하기 전에 변경 사항을 볼 수 있습니까? (0) | 2020.07.04 |
---|---|
Dictionary <>에 항목을 안전하게 추가하는 더 우아한 방법이 있습니까? (0) | 2020.07.04 |
MSBuild를 실행하면 SDKToolsPath를 읽을 수 없습니다. (0) | 2020.07.04 |
CONST를 PHP 클래스에서 정의 할 수 있습니까? (0) | 2020.07.04 |
UIWebView 내에서 Javascript를 디버깅하는 몇 가지 방법은 무엇입니까? (0) | 2020.07.04 |