/// <summary> /// 邮件信息 /// </summary> /// <param name="_username">邮件主题</param> /// <param name="_subject">邮件内容</param> /// <param name="_body">收件人邮件地址</param> /// <param name="_url">邮件内容</param> /// <param name="_emailAddress">收件人邮件地址</param> /// <returns></returns> public void SendMail(string _username, string _subject, string _body, string _url, string _emailAddress) { SmtpClient client = new SmtpClient(); //从配置文件中读取126邮箱的用户名和密码 client.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["mailUser"], ConfigurationSettings.AppSettings["mailPwd"]); client.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["Port"]);//126使用的端口 client.Host = ConfigurationSettings.AppSettings["mailSmtpServer"]; client.EnableSsl = true;//经过ssl加密 try { client.Send(InitMail(_subject, _body, _emailAddress)); } catch (System.Net.Mail.SmtpException ex) { } } /// <summary> /// 邮件信息 /// </summary> /// <param name="Subject">邮件主题</param> /// <param name="Body">邮件内容</param> /// <param name="Address">收件人邮件地址</param> /// <returns></returns> public MailMessage InitMail(string Subject, string Body, string Address) { MailMessage mail = new MailMessage(); //发件人 mail.From = new MailAddress("XXXX@126.com");//发件人的邮箱 //收件人 mail.To.Add(new MailAddress(Address)); //主题 mail.Subject = Subject; //内容 mail.Body = Body; //邮件主题和正文编码格式 mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.BodyEncoding = System.Text.Encoding.UTF8; //邮件正文是Html编码 mail.IsBodyHtml = true; //优先级 mail.Priority = MailPriority.High; //密件抄送收件人 mail.Bcc.Add(Address); //抄送收件人 mail.CC.Add(Address); //添加附件 //mail.Attachments.Add(new Attachment("d:\\tes.txt")); return mail; }