public bool Send(string MessageFrom,string MessageTo, string MessageSubject, string MessageBody)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(MessageFrom);
// message.From = MessageFrom;//发送人地址
message.To.Add(MessageTo);//接受人地址
//string[] mts = MessageTo.Split(';');
//foreach (string s in mts)
//{
// if (string.IsNullOrEmpty(s)) continue;
// message.To.Add(s);
//}
message.Subject = MessageSubject;
message.Body = MessageBody;
message.IsBodyHtml = true;
message.Priority = MailPriority.High;
//string newfileName = "";
//for (int i = 0; i < Request.Files.Count; i++)
//{
// newfileName = Request.Files[i].FileName.ToString();
// message.Attachments.Add(new Attachment(Request.Files[i].InputStream, newfileName));
//}
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.sina.com.cn";
sc.Port = 25;
sc.Credentials = new System.Net.NetworkCredential("用户名", "密码");
try
{
sc.Send(message);
return true;
}
catch (Exception ex)
{
return false;
}
}
C#邮件发送案例
最新推荐文章于 2025-05-31 12:10:36 发布