日期:2014-05-17 浏览次数:20538 次
private void SendMail()
{
MailHelper mh = new MailHelper();
mh.To = "xxx@xx.com";
mh.CC = "xxx@xx.com";
mh.BCC = "xxx@xx.com";
mh.Subject = string.Format(CommonStatic.MAIL_SUBJECT, DateTime.Now.ToString("yyyyMMdd")).ToString();
ArrayList file_name = new ArrayList();
file_name.Add(string.Format(CommonStatic.EXCEL_NAME_ONE, DateTime.Now.ToString("yyyyMMdd")) + CommonStatic.EXCEL_NAME_END);
file_name.Add(string.Format(CommonStatic.EXCEL_NAME_TWO, DateTime.Now.ToString("yyyyMMdd")) + CommonStatic.EXCEL_NAME_END);
mh.Attachments = file_name;
mh.SendEmail(true);
}
MailMessage msgMail = new MailMessage();
msgMail.From = new MailAddress(m_from);
msgMail.To.Add(this.m_to);
if (this.cc.Length > 0)
{
msgMail.CC.Add(this.cc);
}
if (this.bcc.Length > 0)
{
msgMail.Bcc.Add(this.bcc);
}
msgMail.Subject = m_subject;
msgMail.IsBodyHtml = m_IsBodyHtml;
if (m_Attachments != null)
{
for (int i = 0; i < m_Attachments.Count; i++)
{
System.Net.Mail.Attachment mailAttachment = new System.Net.Mail.Attachment(m_Attachments[i].ToString());
msgMail.Attachments.Add(mailAttachment);
}
}
msgMail.Body = m_body;
msgMail.BodyEncoding = m_MailEncoding;
msgMail.SubjectEncoding = m_MailEncoding;
if (verify)
{
msgMail.Headers.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
msgMail.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", m_smtpUserName); //set your username here
msgMail.Headers.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", m_smtpPassword); //set your password here
}
SmtpClient smtp = new SmtpClient(m_smtpServer); //smtp邮件服务器
smtp.Send(msgMail);
msgMail.Dispose();