Apr 29, 2011

C# send mail by smtp with html body

C# send mail by smtp with html body. (add reference System.Net)
using System.Net.Mail;

public static void Sendalertmail(string SendToList, string MailSubJect, string MailBody)
{

string fromEmail = "Administrator@test.com";//sending email from...
string ToEmail = SendToList; //destination email
string body = MailBody;
string subject = MailSubJect;
try
{
MailMessage mm = new MailMessage(fromEmail, ToEmail);
mm.Subject = MailSubJect;
mm.Body = MailBody;
mm.IsBodyHtml = true;
SmtpClient sMail = new SmtpClient("192.168.1.1");//exchange or smtp server goes here.
sMail.DeliveryMethod = SmtpDeliveryMethod.Network;
sMail.Send(mm);
}
catch (Exception ex)
{
//do something
}

}

0 意見: