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

asp.net 群发邮件...

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

namespace Mail
{
    public static class mail
    {
        public static void GetparaBySendmail(string mailaddress,string title,string file ,string content,string fromname,string pwd)
        {
            MailMessage mails = new MailMessage(); //创建邮件类
            string fileone;
            mails.From = new MailAddress(fromname, fromname, System.Text.Encoding.UTF8);//说明指定发件人的信息 收件的地址
            mails.Subject = title;
            fileone=file;
            if (file!=String.Empty) //判断文件是否为空
            {
                AlternateView avfile = new AlternateView(fileone);

                mails.AlternateViews.Add(avfile);
            }
            mails.BodyEncoding = System.Text.Encoding.UTF8;//文件编码
            mails.IsBodyHtml = true;//是否为HTML格式
            mails.Body = content; //发送的内容


            mails.Priority = MailPriority.High;//优先级
            SmtpClient smtp = new SmtpClient(); //发送邮件的协议
            smtp.UseDefaultCredentials=true;
            smtp.Credentials = new System.Net.NetworkCredential(fromname, pwd);//发送人的邮箱
            string host = fromname.Substring(fromname.LastIndexOf("@")+1);
            smtp.Host ="smtp."+ host;
            string[] maillist= mailaddress.Split(';');
            for (int i = 0; i < maillist.Length; i++)
            {
                mails.To.Add(maillist[i]);//收件人的邮箱
            }
           
            try
            {
                smtp.EnableSsl = true;//ssl加密
                //smtp.Timeout = 1200;
                smtp.Send(mails);
                HttpContext.Current.Response.Write(" <script>alert('发送成功'); </script>");


            }
            catch (Exception e)
            {
               
                HttpContext.Current.Response.Write(" <script>alert('"+e.Message+"'); </script>");
            }
        }
    }
}

namespace Mail
{
    public static class mail
    {
        public static void GetparaBySendmail(string mailaddress,string title,string file ,string content,string fromname,string pwd)
        {
            MailMessage mails = new MailMessage(); //创建邮件类
            string fileone;
            mails.From = new MailAddress(fromname, fromname, System.Text.Encoding.UTF8);//说明指定发件人的信息 收件的地址
            mails.Subject = title;
            fileone=file;
            if (file!=String.Empty) //判断文件是否为空
            {
                AlternateView avfile = new AlternateView(fileone);

                mails.AlternateViews.Add(avfile);
            }
            mails.BodyEncoding = System.Text.Encoding.UTF8;//文件编码
            mails.IsBodyHtml = true;//是否为HTML格式
            mails.Body = content; //发送的内容


            mails.Priority = MailPriority.High;//优先级
            SmtpClient smtp = new SmtpClient(); //发送邮件的协议
            smtp.UseDefaultCredentials=true;
            smtp.Credentials = new System.Net.NetworkCredential(fromname, pwd);//发送人的邮箱
            string host = fromname.Substring(fromname.LastIndexOf("@")+1);
            smtp.Host ="smtp."+ host;
            string[] maillist= mailaddress.Split(';');
            for (int i = 0; i < maillist.Length; i++)
            {
                mails.To.Add(maillist[i]);//收件人的邮箱
            }
           
            try
            {
                smtp.EnableSsl = true;//ssl加密
                //smtp.Timeout = 1200;
                smtp.Send(mails);
                HttpContext.Current.Response.Write(" <script>alert('发送成功'); </script>");


            }
            catch (Exception e)
            {
               
                HttpContext.Current.Response.Write(" <script>alert('"+e.Message+"'); </script>");
            }
        }
    }
}


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
asp.net2.0里当readonly遇上enableviewstate=false发布时间:2022-07-10
下一篇:
asp.net本质论学习笔记第一章发布时间: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