Quote:
Posted code will generate an email with multiple zip files as attached but, I need single zip file which compress all the files.
So...you need us to tell you how to move the zip file creation outside a loop, and fill it inside?
That's the kind of thing a third week student on his first computer course should be able to work out on his own in a couple of minutes...
using (ZipFile zip = new ZipFile())
{
foreach (KeyValuePair<string, byte[]> doc in attachmentColl)
{
zip.AddEntry(doc.Key + ".xls", doc.Value);
}
zip.Save(memoryStream);
MemoryStream memoryStream = new MemoryStream();
memoryStream.Position = 0;
Attachment attachment = new Attachment(memoryStream, new ContentType("application/zip")) { Name = doc.Key + ".zip" };
message.Attachments.Add(attachment);
message.To.Add(toAddress);
message.Body = mailbody;
message.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("smtp.XXXXXXXX.net");
smtpClient.Send(message);
}