using System.Net;
using System.Net.Mail;
public void SendMail()
{
string m_strSMTPserver = string.Empty;
string m_strSMTPuser = string.Empty;
string m_strSMTPpwd = string.Empty;
string m_strSMTPsendto = string.Empty;
string m_strSMTPFrom = string.Empty;
lock (ma_ptr.m_cs)
{
m_strSMTPserver = ma_ptr.m_strSMTPserver;
m_strSMTPuser = ma_ptr.m_strSMTPuser;
m_strSMTPpwd = ma_ptr.m_strSMTPpwd;
m_strSMTPsendto = ma_ptr.m_strSMTPsendto;
m_strSMTPFrom = ma_ptr.m_strSMTPfrom;
}
//设置发件人
MailAddress from = new MailAddress(m_strSMTPFrom, @"网站状态查询");
//设置邮件
MailMessage mail = new MailMessage();
//设置标题
mail.SubjectEncoding = Encoding.UTF8;
mail.Subject = string.Format("网站异常状态通知");
//设置邮件内容
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = true;//设置为html格式
string t = @"<p>网站异常状态报告</p><table border=0><tr><th>网站</th><th>状态</th></tr>";
lock (ma_ptr.m_cs)
{
foreach (int i in ma_ptr.m_errList)
{
t = string.Format(@"{0}<tr><td>{1}</td><td>{2}</td></tr>", t, ma_ptr.c_data.Rows[i].Cells[0].Value.ToString(), ma_ptr.c_data.Rows[i].Cells[1].Value.ToString());
}
}
t = string.Format(@"{0}</table><p>made by http://www.xiaocan.me</p>", t);
mail.Body = t;
//设置收件人
mail.To.Add(new MailAddress(m_strSMTPsendto, m_strSMTPsendto));
//设置发件人
mail.From = from;
//设置邮件发送级别
mail.Priority = MailPriority.Normal;
// 设置邮件的附件,将在客户端选择的附件先上传到服务器保存一个,然后加入到mail中
// string fileName = txtUpFile.PostedFile.FileName.Trim();
// fileName = "D:/UpFile/" + fileName.Substring(fileName.LastIndexOf("/") + 1);
// txtUpFile.PostedFile.SaveAs(fileName); // 将文件保存至服务器
// mail.Attachments.Add(new Attachment(fileName));
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
//发送
SmtpClient client = new SmtpClient();
//设置主机名称
client.Host = m_strSMTPserver;
//设置非默认登陆
client.UseDefaultCredentials = false;
//设置验证
client.Credentials = new NetworkCredential(m_strSMTPuser, m_strSMTPpwd);
//处理待发送电子邮件方式
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//送出
try
{
client.Send(mail);
}
catch (Exception ex)
{
}
}