ASP.NET2.0一次发送多封邮件

先导入
using System.Net;
using System.Net.Mail;

    //发送邮件
    public string SendMail(string []toMail,string toSubject,string toBody)
    {
        ////设置发件人信箱,及显示名字
        MailAddress from = new MailAddress("111@163.com", "");
        //设置收件人信箱,及显示名字
        //MailAddress to = new MailAddress(TextBox1.Text, "");


        //创建一个MailMessage对象
        MailMessage oMail = new MailMessage();

        oMail.From = from;
        for (int i = 0; i < toMail.Length-1; i++)
        {
            oMail.To.Add(toMail[i].ToString());
        }


        oMail.Subject = toSubject; //邮件标题
        oMail.Body = toBody; //邮件内容

        oMail.IsBodyHtml = true; //指定邮件格式,支持HTML格式
        oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//邮件采用的编码
        oMail.Priority = MailPriority.High;//设置邮件的优先级为高

        //发送邮件服务器
        SmtpClient client = new SmtpClient();
        client.Host = "smtp.163.com"; //指定邮件服务器
        client.Credentials = new NetworkCredential("111@163.com", "123456");//指定服务器邮件,及密码

        //发送
        try
        {
            client.Send(oMail); //发送邮件
            return "恭喜你!邮件发送成功。";
        }
        catch( Exception e)
        {
            return "邮件发送失败,检查网络及信箱是否可用。" + e.Message;
        }

        oMail.Dispose(); //释放资源

    }

posted on 2008-01-10 08:58  欧尔  阅读(670)  评论(0编辑  收藏  举报

导航