欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net MVC 发送邮件

程序员文章站 2022-10-31 22:33:37
@try {       System.Net.Mail.MailAddress from = new System.Net.M...

@try {
      System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress("www.2cto.com", "ethan"); //填写电子邮件地址,和显示名称

  System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress(www.2cto.com, "jimmy"); //填写邮件的收件人地址和名称
  //设置好发送地址,和接收地址,接收地址可以是多个
  System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
  mail.From = from;
  mail.To.Add(to);
  mail.Subject = "主题内容";
  mail.Body = "你好";
  mail.IsBodyHtml = true;//设置显示htmls
  //设置好发送邮件服务地址
  System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
  client.Host = "smtp.163.com";
  //填写服务器地址相关的用户名和密码信息
  client.Credentials = new System.Net.NetworkCredential("www.2cto.com", "******");
  //发送邮件
      client.Send(mail);
        }
        catch {
            @:<b>发送失败</b>
        }
作者:Cai_Ethan