/// <summary> /// 发送邮件,提供调用 /// </summary> /// <param name="strSendToList">收件人,多个收件人用做好事隔开</param> /// <param name="strSubject">主题</param> /// <param name="strBody">内容</param> /// <param name="strAttachmentsPath">附件路径</param> /// <param name="strOutErr">错误信息</param> /// <returns></returns> public bool SendMail(string strSendToList, string strSubject, string strBody, string[] arrAttachmentsPath, out string strOutErr) { //发送邮件服务器 string strHost = System.Configuration.ConfigurationManager.AppSettings["MailHost"].ToString(); //发件人地址 string strUserMail = System.Configuration.ConfigurationManager.AppSettings["MailSender"].ToString(); //发件人密码 string strUserPwd = System.Configuration.ConfigurationManager.AppSettings["MailSenderPwd"].ToString(); string ss = string.Empty; return SendMail(strHost, strUserMail, strUserPwd, strSendToList, strSubject, strBody, arrAttachmentsPath,out strOutErr); } /// <summary> /// 发邮件 /// </summary> /// <param name="strMailService">邮箱服务器</param> /// <param name="strSendMail">发件人邮箱</param> /// <param name="strSendMailPwd">发件人密码</param> /// <param name="strToList">收件人,多个收件人用做好事隔开</param> /// <param name="strSubject">主题</param> /// <param name="strMessage">邮件内容</param> /// <param name="AttachFile">附件路径</param> public bool SendMail(string strMailService, string strSendMail, string strSendMailPwd, string strToList, string strSubject, string strMessage, string[] AttachFile, out string strOutErr) { System.Net.Mail.SmtpClient client = new SmtpClient(strMailService); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(strSendMail, strSendMailPwd); client.DeliveryMethod = SmtpDeliveryMethod.Network; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(strSendMail, strToList); message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = strSubject; message.Body = strMessage; message.IsBodyHtml = true; //在有附件的情况下添加附件 if (AttachFile != null && AttachFile.Length > 0) { foreach (string path in AttachFile) { var attachFile = new Attachment(path); message.Attachments.Add(attachFile); } } try { client.Send(message); strOutErr = string.Empty; } catch (Exception err) { strOutErr = err.Message; return false; } return true; }