Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Zip Archive Corrupts File

Status
Not open for further replies.

Meleagant

Programmer
Aug 31, 2001
166
0
0
US
All,

My web app sends many many emails. Usually PDF, Excel, Word, etc. This is the first time I need to send a Zip file. Every time I send I zip file through code, when I get the zip in my email, then try to unzip it, I get a message saying that the CRC is bad and the file is corrupt. Interestingly enough, *.Rar files come through fine. But I can't use these as I cannot guarantee our clients use WinRar.

Anyone ever have any success sending an email with a zip file attachment in Asp.Net using IIS? I've tried sending through our Exchange server as well as through the Smtp host of the T1 provider. Same results, everytime the zip file in the email is corrupt.

For those interested here is a simplified version of the sub that I use to send the email:
Code:
    Private Sub SimpleSendEmail()

        Dim NetworkCred As NetworkCredential = New System.Net.NetworkCredential()
        NetworkCred.UserName = "MyEmail@Domain.com"
        NetworkCred.Password = "MyPassword"

        Dim oEmail As New System.Net.Mail.MailMessage()
        oEmail.From = New MailAddress("MyEmail@Domain.com")
        oEmail.To.Add("MyEmail@Domain.com")
        oEmail.Subject = "This is an email"
        oEmail.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>"
        oEmail.IsBodyHtml = True
        oEmail.Priority = System.Net.Mail.MailPriority.High

        Dim oClient As New SmtpClient("smtp.server.com")
        oClient.UseDefaultCredentials = True
        oClient.Port = 587
        oClient.EnableSsl = True
        oClient.Credentials = NetworkCred

        Dim oAttachment As System.Net.Mail.Attachment
        oAttachment = New System.Net.Mail.Attachment("C:\Temp\SampleFile.zip")
        oAttachment.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable
        oEmail.Attachments.Add(oAttachment)

        Try
            oClient.Send(oEmail)

        Catch ex As Exception
            Dim ai As New AddlErrInfo
            ai.Add("Host", oClient.Host)
            ai.Add("Port", oClient.Port.ToString)
            AppError.GenericApplicationError(ex, ai)

        Finally
            oEmail = Nothing
            oClient.Dispose()

        End Try

    End Sub

* Sine scientia ars nihil est
* Respondeat superior
 
try removing the transfer coding, and possibly setting other properties of the attachment (size, content type, etc). I would assume the problems is how the client is instructed to decode the attachment, not the attachment itself.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
I did have a problem a couple of weeks back with IIS7 & Asp .Net 4.0 not sending emails where the attachment was larger than 3MB (in my case mainly Excel files 3 - 5MB). According to MS, I should add the Transfer Encoding property to the attachment. The article is located here.

With this app I am programmatically creating the Zip archive which is saved to disk, for now C:\Temp on the web server. The file is then attached to the email. If I try to extract the zip archive that is created in C:\Temp, it extracts fine, no issues with it. It seems that only when that file is emailed it gets corrupted.

In the recent hours I've also found out that sending Zip files that are less than 3MB extract fine when emailed. It seems that the Zips that are over 3MB will give me the bad CRC, file corrupt messages.

I'll try removing the Transfer Encoding, and playing with some of the other properties. Thanks for the help!!

* Sine scientia ars nihil est
* Respondeat superior
 
sounds like a configuration issue then. either your email server or the recipient's email server (if different) has a file size limit on attachments. That would explain the errors you are receiving.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top