/// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="strto">收件人</param>
        /// <param name="strSubject">主题</param>
        /// <param name="strBody">内容</param>
        /// <param name="strAttach">附件</param>
        public void SendSMTPEMail(string strto, string strSubject, string strBody, string strAttach)
        {
            string SMTPHost = ConfigurationManager.AppSettings["SMTPHost"];
            //SMTPHost  SMTP smtp.163.com
            string SMTPPort = ConfigurationManager.AppSettings["SMTPPort"];
            //SMTPPort 端口110
            string SMTPUser = ConfigurationManager.AppSettings["SMTPUser"];
            string SMTPPassword = ConfigurationManager.AppSettings["SMTPPassword"];
            //SMTPUser ,SMTPPassword 上面两个是163邮箱的账号密码
            string MailFrom = ConfigurationManager.AppSettings["MailFrom"];
            //MailFrom 这个是发信人 就是163账号
            string MailSubject = ConfigurationManager.AppSettings["MailSubject"];
            //MailSubject 主题
            string MailAttach = ConfigurationManager.AppSettings["MailAttachment"];
            //MailAttach 附件            MailSubject = strSubject;            Attachment mailAttach;
            mailAttach = new Attachment(strAttach);
            SmtpClient client = new SmtpClient(SMTPHost);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;            MailMessage message = new MailMessage(MailFrom, strto, MailSubject, strBody);
            message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
            message.IsBodyHtml = true;
            message.Attachments.Add(mailAttach);            client.Send(message);
        }
这个只能单发邮件,添加一个附件。
  怎么才能实现群发邮件跟添加多个附件呢???
   

解决方案 »

  1.   


     string MailAttach = ConfigurationManager.AppSettings["MailAttachment"];
                //MailAttach 附件附件的话我是给的路径
    我拼接了下字符串  两个路径之间 用分号隔开了
    mailAttach = new Attachment(strAttach);
    但是这一句报错了"不支持给定路径的格式。"
       怎么弄?
     谁来说点实际的东西
      

  2.   


    // 假设多个文件附件
    for (int i = 0; i < Args.AttachmentFileName.Length; i++)
    {
        MailMessage Msg      = new MailMessage();    ......................
        ......................    ......................    ......................    ......................    
    System.Net.Mime.ContentType cType = new System.Net.Mime.ContentType();
    cType.Name  = 文件名称,将来会显示在邮件的附件列表中;
        // 利用MemoryStream逐一读取文件
        Msg.Attachments.Add(new Attachment(MemoryStream 读取文件对象, cType));
    }如果群发,机开个线程逐一发送即可,也可以多线程。
    我以前写的是windows服务3-16线程群发线程开多了也没用。。几个就够了