【文件属性】:
文件名称:.net 公共类
文件大小:70KB
文件格式:CS
更新时间:2016-06-29 09:23:21
.net 公共类
///
/// 电子邮件发送 没有附件
///
/// 发件人邮箱
/// 发件人密码
/// 邮件主题
/// 邮件正文
/// 收件人邮箱
///
public static bool sendmail(string frommail,string pwd,string subject,string body, string tomail)
{
bool bol = false;
string das = DateTime.Now.Year.ToString();
if (true)
{
try
{
MailAddress to = new MailAddress(tomail);
MailAddress from = new MailAddress(frommail);
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = body;
//
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = true;
smtp.Port = 25;
string[] name = frommail.Split('@');
string names = name[0];
smtp.Credentials = new NetworkCredential(names, pwd);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = "smtp.163.com";
SmtpClient client = new SmtpClient("smtp.163.com", 587);
client.EnableSsl = true;
message.To.Add(tomail);
smtp.Send(message);
bol = true;
}
catch (Exception ex)
{
bol = false;
}
}
return bol;
}