开发者

Adding a html file into a c# email app

using System;
using System.Net;
using System.Net.Mail;

class MainClass
{
    public static void Main(string[] args)
    {
        SmtpClient client = new SmtpClient("192.168.1.12", 25);


        using (MailMessage msg = new MailMessage())
        {
            msg.From = new MailAddress("no开发者_运维技巧reply@test.com");
            msg.Subject = "***Dexter DB***";

            msg.Body = "***DB backup done***"; // I want to change this so i can do this in html file - how do i pick up this file and send a html form?

            msg.To.Add(new MailAddress("test@test.com"));
            client.Send(msg);
        }
    }
}


msg.IsBodyHtml = true;


Construct a Mulipart Mime Message, using the System.Net.Mail.Attachment class. The part containing HTML has a mime type of text/html. You can modify the example on the reference page to specify a part without disposition and filename.


Off the top of my head

msg.Body = File.ReadAllText("c:\\temp\\somefile.html");
msg.IsBodyHtml = true;

However, if this page has a HTML form in it, it may not work in some mail clients, as some mail clients strip this functionality from the mail before it is displayed to the recipient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜