[邮件]发送多人MAIL类

    public static void mailadd(string mailto, string mailsubject, string mailbody, string attech)//创建Mail,填入发送人,主题,內容
    {
        {
        MailMessage mlMsg = new MailMessage();        
        //处理多个收件人
         string[] toArray = mailto.Split(',');
        foreach (string i in toArray)
        {
           mlMsg.To.Add(new MailAddress(i));
        }

        mlMsg.Subject = mailsubject;
        mlMsg.Body = mailbody;
        mlMsg.IsBodyHtml = true;
        mlMsg.From = new MailAddress("workflowweb@shinhint.gd.cn","Automatic(自动化)");


        //附件
         if (attech != "") 
        {
            string[] attArray = attech.Split(',');
            foreach (string a in attArray)
            {
                string strFilePath = @a;
                Attachment attachment1 =
                        new Attachment(strFilePath);
                attachment1.Name = System.IO.Path.GetFileName(strFilePath);
                //attachment1.NameEncoding = Encoding.UTF8;
                attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

                ////内嵌式附件
                //attachment1.ContentDisposition.Inline = true;
                //attachment1.ContentDisposition.DispositionType =
                //   System.Net.Mime.DispositionTypeNames.Inline;

                //attachment1.
                mlMsg.Attachments.Add(attachment1);
            }
        }

        SmtpClient smtpClient = new SmtpClient("mailshinhint.shinhint");
        smtpClient.Credentials = new NetworkCredential("workflowweb", "1234");
            
        //smtpClient.Timeout = 1000;
            
        smtpClient.EnableSsl =false;
        smtpClient.Send(mlMsg);
        }
       // catch {}

    }

}
发布了932 篇原创文章 · 获赞 391 · 访问量 330万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览