发送邮件的代码~

在load事件中引用sendmail方法~~经本人测试过~ 

private void Sendmail()
        {

            try
            {
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
                msg.To.Add("106233153@qq.com");//这个是收件人的地址
                msg.From = new MailAddress("xxxxx@163.com", "弟弟", System.Text.Encoding.UTF8);这个是发件人的地址
                msg.Subject = "这是我自己写的发邮件的代码";//邮件标题
                msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
                msg.Body = "<DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><div style='width:710px; margin:0 auto;'><div style='height:65px; border-bottom:2px solid #ccc;'><div style='float:left;'><img src=' http://www.oachina.com/images/logo.jpg' /></div><div style='float:right; margin-top:40px;'><a href=' http://www.oachina.com' target='_blank' style='color:#2b7be8;'>首页</a></div></div><DIV style='FONT-SIZE: 14px; MARGIN: 10px; LINE-HEIGHT: 40px'><DIV>亲爱的用户:</DIV><DIV>您好!</DIV><DIV>设置验证邮箱、设置密码保护问题将更好地保障您的帐号安全。</DIV><DIV>感谢您使用!</DIV><DIV>中办网个人中心</DIV><DIV>" + DateTime.Now.ToShortDateString() + "</DIV></DIV><div style='height:1px; background-color:#eaeaea;overflow:hidden; clear:both;'></div><DIV style='FONT-SIZE: 12px; TEXT-ALIGN: center; height:25px; line-height:25px;'>&copy;OAchina</DIV></div>";//邮件内容
                msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
                msg.IsBodyHtml = true;//是否是HTML邮件
                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("xxxxx@163.com", "password");
                client.Host = "smtp.163.com";

                client.Send(msg);
                Response.Write("发送Success");
            }
            catch (Exception e)
            {
                Response.Write("发送fail");
            }
            finally
            {
                Response.Write("发送了");
            }

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值