• Asp.net(c#)发送电子邮件
  •  2009/5/20 3:11:49 | 分类:ASP | 阅读:573
  • 导读:usingystemwebail;ailessagemsg=newailessage();//发送方地址(如)msgrom=;//接收方地址(如)msgo=;//正…

  • using System.web.Mail; 

                MailMessage msg = new MailMessage();
                //发送方地址(如)
                msg.From = "";
                //接收方地址(如)
                msg.To = "";
                //正文内容类型
                msg.BodyFormat = MailFormat.Html;
                //正文内容编码
                msg.BodyEncoding = System.Text.Encoding.Default;
                //主题
                msg.Subject = "张大宇向您问好";
                //内容
                msg.Body = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv=Content-Type content=text/html; charset=gb2312><style type=text/Css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>用户名:" + UserName.Text.Trim() + "</font><br><font color=green>密码:" + strUserPsw.ToString() + "</font><br><b>验证地址:</b><a href=http://192.168.1.98/AllFiles/Member/CheckFromEmail.ASPx?UserName=" + UserName.Text.Trim() + "target=_blank>http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "</a>。如果您不能点击链接进行跳转,请把这个地址粘贴到浏览器的地址栏直接访问。<br><font color=red>此邮件不必回复,谢谢。</font></body></html>";



                //设置为需要用户验证
                msg.Fields.Add("", "1");

                //设置验证用户名
                msg.Fields.Add("", "zdyguilong");
                //设置验证密码
                msg.Fields.Add("", "123456");
                //邮件服务器地址(如smtp.163.com)
                SmtpMail.SmtpServer = "smtp.163.com";
                //发送
                SmtpMail.Send(msg);
                //Response.Write("<script language=javascript>alert(注册成功);window.location=../default.aspx</script>");

    CQZOL


    (学 习 吧:www.xuexibar.cn)

    此文章为学 习 整理或来自网络,内容仅供访问者参考,版权归原作者所有,转载请注明出处!