关闭

群发送邮件类

290人阅读 评论(0) 收藏 举报

。Net2.0下的,要求服务期验证。代码如下:

引用不用说了   

 public class Mail
    {
        private string subject;
        private string[] mailTo;
        private string body;
        private string smtpServer;
        private string user;
        private string password;
        private string sender;

        public Mail(string Subject,string[] MailTo,string Sender,string Body,string SMTP,string User,string Pass)
        {
            this.subject = Subject;
            this.mailTo = MailTo;
            this.body = Body;
            this.smtpServer = SMTP;
            this.user = User;
            this.password = Pass;
            this.sender = Sender;
        }
        public bool Send()
        {
            bool Flag = true;
            try
            {
                System.Net.Mail.MailMessage mailObj = new System.Net.Mail.MailMessage();

                //Add MailTo address
                for (int i = 0; i < mailTo.Length; i++)
                {
                    mailObj.To.Add(mailTo[i]);
                }
                mailObj.IsBodyHtml = true;
                mailObj.Subject = subject;
                string From = user + "@" + smtpServer.Substring(smtpServer.IndexOf(".") + 1, smtpServer.Length - smtpServer.IndexOf(".") - 1);
                mailObj.From = new MailAddress(From, sender, System.Text.Encoding.UTF8);
                mailObj.Body = body;
                System.Net.Mail.SmtpClient SmtpMail = new SmtpClient(smtpServer);
                SmtpMail.Credentials = new System.Net.NetworkCredential(From, password);
                SmtpMail.Send(mailObj);
                Flag = true;
            }
            catch
            {
                Flag = false;
            }
            return Flag;           
        }
    } 

 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:160019次
    • 积分:2500
    • 等级:
    • 排名:第15291名
    • 原创:63篇
    • 转载:106篇
    • 译文:0篇
    • 评论:38条