asp.net邮件发送

  命名空间要加上"using System.Net.Mail;"

 public void Send_Email(){

  MailMessage mailMsg = new MailMessage();
            //设置正文格式
            mailMsg.From = new MailAddress("[email protected]");
            mailMsg.To.Add(new MailAddress("[email protected]"));
            mailMsg.IsBodyHtml = true;
            mailMsg.Subject = "test";//主题
            mailMsg.Body = "test";//内容

              try {
                //设置发送邮件服务器           
                SmtpClient mclient = new SmtpClient();
                mclient.Send(mailMsg);

            }
            catch (Exception err) {
                Response.Write("发送失败" + err.Message.ToString());
            }

   }

还要在web.config配置文件添加: <system.net>
        <mailSettings>
            <smtp from="[email protected]">
                <network host="smtp.126.com" password="2963359"  port="25"    userName="[email protected]" defaultCredentials="false"/>
            </smtp>
        </mailSettings>
    </system.net>

 

你可能感兴趣的:(.net,Web,Yahoo,asp.net,asp)