日期:2014-05-18 浏览次数:21144 次
/// <summary> /// 发送邮件功能 /// </summary> /// <param name="fromEmail">登录邮箱</param> /// <param name="password">登录密码</param> /// <param name="user">邮件昵称</param> /// <param name="title">邮件标题</param> /// <param name="toEmail">邮件地址</param> /// <param name="email">邮件内容</param> /// <param name="smtpServer">smtp服务器</param> public bool SendMessage(string fromEmail,string password, string user, string title, string toEmail, string email,string smtpServer) { try { SmtpClient smtp = new SmtpClient(); //实例化一个SmtpClient smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //将smtp的出站方式设为 Network smtp.EnableSsl = false;//smtp服务器是否启用SSL加密 smtp.Host = smtpServer;//指定 smtp 服务器 smtp.Credentials = new NetworkCredential(fromEmail, password); MailMessage mm = new MailMessage(); //实例化一个邮件类 mm.Priority = MailPriority.High; //邮件的优先级,分为 Low, Normal, High,通常用 Normal即可 mm.From = new MailAddress(fromEmail, user, Encoding.GetEncoding(936)); mm.CC.Add(new MailAddress(toEmail, "", Encoding.GetEncoding(936))); mm.Subject = title; //邮件标题 mm.SubjectEncoding = Encoding.GetEncoding(936); mm.IsBodyHtml = true; //邮件正文是否是HTML