当前位置: 编程技术>.net/c#/asp.net
asp.net 发送邮件的简单示例
来源: 互联网 发布时间:2014-08-30
本文导语: 完整代码如下。 代码示例: /// /// 发送邮件 /// /// 邮件服务器地址[qq:smtp.qq.com,yeah.net:smtp.yeah.net,163:smtp.163.net] /// 邮件服务器账号 /// 邮件服务器密码 /// 发送邮件地址 /// 接收邮件地址 /// 邮件内容 /// 邮件主题 public ...
完整代码如下。
代码示例:
///
/// 发送邮件
///
/// 邮件服务器地址[qq:smtp.qq.com,yeah.net:smtp.yeah.net,163:smtp.163.net]
/// 邮件服务器账号
/// 邮件服务器密码
/// 发送邮件地址
/// 接收邮件地址
/// 邮件内容
/// 邮件主题
public static void SendMail(string smtpAddress, string serverAcount, string serverPassword, string fromEmail, string toEmail, string emailContent, string emailSubject)
{
SmtpClient smtp = new SmtpClient(smtpAddress);
smtp.Credentials = new NetworkCredential(serverAcount, serverPassword);
MailAddress fromEmailAdd = new MailAddress(fromEmail);
MailAddress toEmailAdd = new MailAddress(toEmail);
MailMessage message = new MailMessage(fromEmailAdd, toEmailAdd);
message.IsBodyHtml = true;
message.Body = emailContent;
message.Subject = emailSubject;
smtp.Send(message);
}
/// 发送邮件
///
/// 邮件服务器地址[qq:smtp.qq.com,yeah.net:smtp.yeah.net,163:smtp.163.net]
/// 邮件服务器账号
/// 邮件服务器密码
/// 发送邮件地址
/// 接收邮件地址
/// 邮件内容
/// 邮件主题
public static void SendMail(string smtpAddress, string serverAcount, string serverPassword, string fromEmail, string toEmail, string emailContent, string emailSubject)
{
SmtpClient smtp = new SmtpClient(smtpAddress);
smtp.Credentials = new NetworkCredential(serverAcount, serverPassword);
MailAddress fromEmailAdd = new MailAddress(fromEmail);
MailAddress toEmailAdd = new MailAddress(toEmail);
MailMessage message = new MailMessage(fromEmailAdd, toEmailAdd);
message.IsBodyHtml = true;
message.Body = emailContent;
message.Subject = emailSubject;
smtp.Send(message);
}