我要给 942426801@qq.com 这个用户发一个邮件 内容是 密码: aaaaaa 请问如何实现这个功能,请给出一个可以实现这个功能的代码,我只要实现这个功能的代码就行了,请测试过后在贴出代码!
非常感谢!!
public static bool SendMail(string address, string subject, string body, bool isBodyHtml)
{
StringDictionary dic = SettingUtil.LoadSettings();
if (dic == null)
return SendMailResult.Fail;
string host = dic["smtpserver"];
string port = dic["smtpserverport"];
string ssl = dic["enablessl"];
string userid = dic["smtpusername"];
string pwd = dic["smtppassword"];
string replyto = dic["replyto"];
MailMessage objMail = new MailMessage();
objMail.To.Add(address);
objMail.From = new MailAddress(userid, userid, Encoding.UTF8);
objMail.Subject = subject;
objMail.SubjectEncoding = Encoding.UTF8;
objMail.Body = body;
objMail.IsBodyHtml = isBodyHtml;
objMail.Priority = MailPriority.High;
if (!string.IsNullOrEmpty(replyto))
objMail.ReplyTo = new MailAddress(replyto);
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(userid, pwd);
client.Host = host;
client.Port = int.Parse(port);
if (ssl.Equals("false", StringComparison.CurrentCultureIgnoreCase))
client.EnableSsl = false;
else
client.EnableSsl = true;
try
{
client.Send(objMail)
}
return true;
}
catch (SmtpException ex)
{
return false;
}
}
建一个发email的类,然后把你要发信息与地址传进去不就可以发了吗? .net发email有很简单的,网上很多这样的代码,可以用自己的SMTP服务器,也可以用163,21cn,qq这些SMTP
Web.config
Default.aspx
Default.aspx.cs
App_Code/Utility.cs
App_Code/AlertMessage.cs