邮件发送

public ActionResult Index()
{
    MailMessage mailMessage = new MailMessage();//导入system.net这个Assembly
    mailMessage.From = new MailAddress("发件人邮箱地址","我是谁");
    mailMessage.To.Add(new MailAddress("收件人邮箱地址", "我是一个好人"));//可以有多个收件人发件人邮箱地址
    mailMessage.Subject = "这是邮件标题";
    mailMessage.Body = "<a href='http://www.baidu.com'>测试页面</a>";
    mailMessage.IsBodyHtml = true;
    //mailMessage.Bcc = "";
    //mailMessage.CC = "";
    //mailMessage.From;
    //mailMessage.To;
    //mailMessage.Sender;
    //mailMessage.IsBodyHtml = true;
    //指定SMTP服务地址
    SmtpClient client = new SmtpClient("smtp.163.com");
    client.Credentials = new NetworkCredential("发件人邮箱名称", "发件人邮箱密码");
    client.Send(mailMessage);
    return Content("发送成功");
}

 

posted @ 2016-06-24 23:16  黄者之风  阅读(160)  评论(0编辑  收藏  举报