标签:方式 use div system timeout 服务 priority public sys
/// <summary> /// 发送邮件 /// </summary> /// <param name="from">发件人邮箱</param> /// <param name="fromname">发件人姓名</param> /// <param name="to">收件人地址</param> /// <param name="subject">标题</param> /// <param name="body">内容</param> /// <param name="username">发件人账号</param> /// <param name="password">发件人密码</param> /// <param name="server">发件服务器</param> /// <param name="port">端口</param> /// <returns></returns> public static bool SendMail(string from, string fromname, string to, string subject, string body, string username, string password, string server,int port=25) { try { //邮件发送类 MailMessage mail = new MailMessage(); //是谁发送的邮件 mail.From = new MailAddress(from, fromname); //发送给谁 mail.To.Add(to); //标题 mail.Subject = subject; //内容编码 mail.BodyEncoding = Encoding.Default; //发送优先级 mail.Priority = MailPriority.High; //邮件内容 mail.Body = body; //是否HTML形式发送 mail.IsBodyHtml = true; //邮件服务器和端口 SmtpClient smtp = new SmtpClient(server, port); smtp.UseDefaultCredentials = true; //指定发送方式 smtp.DeliveryMethod = SmtpDeliveryMethod.Network; //指定登录名和密码 smtp.Credentials = new System.Net.NetworkCredential(username, password); //超时时间 smtp.Timeout = 10000; smtp.Send(mail); return true; } catch (Exception exp) { //return exp.Message; return false; } }
标签:方式 use div system timeout 服务 priority public sys
原文地址:http://www.cnblogs.com/testsec/p/6095659.html