Asp.net 2.0 发送邮件
相关命名空间:
using System.Net;
using System.Net.Mail;
核心代码示例:using System.Net.Mail;
protected void Page_Load(object sender, EventArgs e)
{
MailMessage MM = new MailMessage();
MM.To.Add("hooyes@vip.qq.com,lovehooyes@126.com"); //收件人地址,可多个用逗号隔开
MM.Subject = "邮件标题";
MM.Body = "邮件内容";
MM.From = new MailAddress("you@gmail.com", "西狐测试");
SmtpClient mClient = new SmtpClient();
mClient.Credentials = new NetworkCredential("hooyes", "hooyesPwd"); //用户名密码
mClient.Port = 587;
mClient.Host = "smtp.gmail.com"; //邮件smtp服务器
mClient.EnableSsl = true;//是否用SSL加密
try
{
mClient.Send(MM);
Response.Write("发送成功");
}
catch (SmtpException ex)
{
Response.Write(ex.Message);
}
}
{
MailMessage MM = new MailMessage();
MM.To.Add("hooyes@vip.qq.com,lovehooyes@126.com"); //收件人地址,可多个用逗号隔开
MM.Subject = "邮件标题";
MM.Body = "邮件内容";
MM.From = new MailAddress("you@gmail.com", "西狐测试");
SmtpClient mClient = new SmtpClient();
mClient.Credentials = new NetworkCredential("hooyes", "hooyesPwd"); //用户名密码
mClient.Port = 587;
mClient.Host = "smtp.gmail.com"; //邮件smtp服务器
mClient.EnableSsl = true;//是否用SSL加密
try
{
mClient.Send(MM);
Response.Write("发送成功");
}
catch (SmtpException ex)
{
Response.Write(ex.Message);
}
}