• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ASP.NET发送邮件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

公用方法

 


        /// <summary>
        /// 发激活码邮件
        /// </summary>
        /// <param name="emailInfo">邮件</param>
        public void sendEmail(FilmSys.Model.EmailInfo emailInfo)
        {
            try
            {
                //编码暂硬性规定为GB2312
                Encoding encoding = Encoding.GetEncoding(936);
                MailMessage Message = new MailMessage(
                new MailAddress(emailInfo.SendEmailAddress, emailInfo.SendEmailName, encoding),//第一个是发信人的地址,第二个参数是显示的发信人   new MailAddress("[email protected]", "西安集天电子科技服务公司", encoding)
                new MailAddress(emailInfo.ReceiveEmailAddress));//收信人邮箱
                Message.SubjectEncoding = encoding;
                Message.Subject = emailInfo.Subject;//"西安集天电子科技服务公司欢迎您的加入";//标题
                Message.BodyEncoding = encoding;
                Message.IsBodyHtml = true;//邮箱主体识别html语言
                Message.Body = emailInfo.Content;//"请进行邮箱验证来完成您注册的最后一步,点击下面的链接激活您的帐号:<br><a target='_blank' rel='nofollow' style='color: #0041D3; text-decoration: underline' href='http://www.XXX.com/regedit/regeditOK.aspx?code=" + numCode + "&u
                smtpClient.Credentials = new NetworkCredential(emailInfo.SendEmailAddress, emailInfo.SendEmailPwd);//信箱的用户名和密码
                smtpClient.Timeout = 999999;
                smtpClient.Send(Message);
            }
            catch (Exception)
            {
                //throw new Exception(ex.Message);
            }
        }

 

 


实体类

    public class EmailInfo
    {
        private string sendEmailAddress;

        public string SendEmailAddress
        {
            get { return sendEmailAddress; }
            set { sendEmailAddress = value; }
        }


        private string sendEmailName;

        public string SendEmailName
        {
            get { return sendEmailName; }
            set { sendEmailName = value; }
        }


        private string sendEmailPwd;

        public string SendEmailPwd
        {
            get { return sendEmailPwd; }
            set { sendEmailPwd = value; }
        }

        private string receiveEmailAddress;

        public string ReceiveEmailAddress
        {
            get { return receiveEmailAddress; }
            set { receiveEmailAddress = value; }
        }


        private string subject;

        public string Subject
        {
            get { return subject; }
            set { subject = value; }
        }


        private string content;

        public string Content
        {
            get { return content; }
            set { content = value; }
        }

        private string smtpClient;

        public string SmtpClient
        {
            get { return smtpClient; }
            set { smtpClient = value; }
        }


        private string numCode;

        public string NumCode
        {
            get { return numCode; }
            set { numCode = value; }
        }


        private string userid;

        public string Userid
        {
            get { return userid; }
            set { userid = value; }
        }

    }

 

 


调用方法  加上try catch()


     string userEmail = dt.Rows[i]["userEmail"].ToString();
                            //发送邮件
                            FilmSys.Model.EmailInfo emailInfo = new FilmSys.Model.EmailInfo();
                            emailInfo.SendEmailAddress = "[email protected]";//发件人地址
                            emailInfo.SendEmailName = "云轩阁电影网";//发件人名称
                            emailInfo.SendEmailPwd = "mv123456";//发件人密码
                            emailInfo.ReceiveEmailAddress = userEmail;//收件人地址
                            emailInfo.SmtpClient = "smtp.163.com";//邮箱服务器smtp.163.com smtp.qq.com
                            emailInfo.Subject = this.EmailTitle.Text;//邮件标题
                            emailInfo.NumCode = "";//自动生成的验证号
                            emailInfo.Userid = "";//用户id
                            emailInfo.Content = this.CKfilmContent.Text;//邮件内容 可以使用html
                            sendEmail(emailInfo);


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ASP.NET Word/Excel 权限问题发布时间:2022-07-10
下一篇:
Pro ASP.NET MVC –第五章 使用Razor发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap