发送带有图像附件的多封邮件

时间:2011-06-08 11:11:13

标签: c# email

我正在使用邮件类将附件作为图像的电子邮件发送给多个收件人。 但问题是,当电子邮件被发送给第一个收件人时,它会抛出“另一个进程正在使用图像”的例外情况......如何解决这个问题..

我在listitem中获得用户:

 foreach (ListItem item in lstboxlist.Items)
                {
                    to = Convert.ToString(item);
                    select_theme_tosend(to, sub);
                }

我正在向用户发送邮件:

string source_theme =  theme;
            string dest_theme_path = "xxx";

            if (File.Exists(dest_theme_path))
            {
                File.Delete(dest_theme_path);
            }
            File.Copy(source_theme, dest_theme_path);
            xmlDoc.Load(theme);
            XmlNode node = null;
            SendMail_Html send_html = new SendMail_Html ();

                MailMessage mail = new MailMessage();
                Attachment footer_att = null;
                Attachment header_att = null;
                Attachment other_att = null;
                mail.Attachments.Add(other_att);
                }
                xmlDoc.Save(theme);

                StreamReader strm_rdr = new StreamReader(theme);
                string theme_text = strm_rdr.ReadToEnd();

                SendMail send_mail = new SendMail();
                send_html.sent_htmlmail1(to, theme_text, subject, footer_att, header_att, other_att);
                mail.Dispose();
               // File.Delete(header_path);
               // File.Delete(other_imagepath);
               // File.Delete(foot_image_path);  
}  

如果我取消注释最后一行,则在向第二个地址发送邮件时显示错误: “无法找到指定的文件”...... 我该怎么做才能发送多封电子邮件...... 请帮忙......

1 个答案:

答案 0 :(得分:1)

完成后关闭流,例如:

StreamReader strm_rdr = new StreamReader(theme);
string theme_text = strm_rdr.ReadToEnd();
strm_rdr.Close();