Reputation: 1903
I have use ICSharpCode.SharpZipLib.Zip library for creating Zip file it's working fine, but when i have attach this Zip file to mail attachment, mail is not sent due to attached zip file,
here is code for attaching zip file to mail
System.Net.Mail.Attachment attachment = null;
try
{
MemoryStream memoryStream = new MemoryStream();
attachment = new System.Net.Mail.Attachment(memoryStream, "test.zip");
}
catch (Exception e)
{
return false;
}
please know me how i can send zip file through mail?.
Upvotes: 0
Views: 577
Reputation: 6490
There could be lot of reasons for the issue,
Upvotes: 0
Reputation: 150138
Your code
MemoryStream memoryStream = new MemoryStream();
attachment = new System.Net.Mail.Attachment(memoryStream, "test.zip");
passes a Stream, but that Stream is empty (there's nothing in memoryStream
).
If you want to use a MemoryStream, you must read the contents of the ZIP file into memory. You can also use a FileStream if the ZIP is already on disk.
If using a MemoryStream, be sure and set its position 0.
memoryStream.Position = 0;
Depending on how you are using SharpZipLib, you may have access to a ZipOutputStream. If you do, I think you could use that.
Upvotes: 1