asp.net 发送邮件的简单示例

发布时间:2020-01-08编辑:脚本学堂
asp.net程序发送邮件的一段代码,很简单,主要是用到了smtpclient,有需要的朋友,可以参考下。

完整代码如下。
 

复制代码 代码示例:
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="smtpAddress">邮件服务器地址[qq:<span style="color: #ff0000;">smtp.qq.com</span>,yeah.net:<span style="color: #ff0000;">smtp.yeah.net,163:smtp.163.net</span>]</param>
/// <param name="serverAcount">邮件服务器账号</param>
/// <param name="serverPassword">邮件服务器密码</param>
/// <param name="fromEmail">发送邮件地址</param>
/// <param name="toEmail">接收邮件地址</param>
/// <param name="emailContent">邮件内容</param>
/// <param name="emailSubject">邮件主题</param>
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);
  }