Hi everyone / Dave!
Email I send contain corrupt attachments - soemtimes !
Here are the conditions under which the problem occurs :
- OS Windows 2000 5.00.2195 SP4
- .Net framework v1.1.4322
- attached file must be binary (e.g. *.jpg, *.pdf)
- attached file must be over a certain size (from - experimentation, a jpeg of 76 KB or smaller comes across intact but one of 99 KB or larger comes across corrupt ?! so the “line” is somewhere in between those two figures…?!)
- the application (site) must be impersonating an account (<identity impersonate="true"/>)
- Changing the <identity impersonate="false"/>) fixes the problem…?!?!
- the user I choose to impersonate does not seem to make a difference
the optional encoding parameter in the MailAttachment constructor (MailEncoding.UUEncode OR MailEncoding.Base64) does not seem to make a difference either
- the problem occurs when the mail is sent 1. from my machine, 2. from a Test server and 3. from the Production server
Other interesting facts are :
- I can confirm that the actual service account(s) being impersonated has the appropriate permission to send a file (I have logged in under those account and successfully sent that same attachment)
- This situation occurred in two separate environments (two different clients !) with exactly the same “symptoms”
- Outlook indicates that the attached file has a size of 64 B (bytes ?) but once saved on disk, Windows indicates 0 bytes (Size AND Size on disk).
- The service account being impersonated has “Full Control” permission on the directory containing the file (necessary for the MailAttachment constructor to work)
- I have “played around” with some the my SMTP Virtual Server settings (e.g. Authentification, etc.) and it did not seem to make a difference
- I have moved the .vb file containing the code from the class library project to my web project with the same results
I have done a lot of research on the Net and have not found anything comparable to my situation – which I find surprising since it happens to me in two separate environments and is bound to have happened to someone else somewhere !)
Here is a sample of the code I use :
-----------------------
Public Sub Send(Optional ByVal blnRecordNotifications As Boolean = False)
Dim oMessage As MailMessage
Dim oAttachment As MailAttachment
Dim strItem As String
Const ORIGIN = "Send"
Try
' Instanciate the .Net Framework used for sending e-mails
oMessage = New MailMessage
' Sets all relevant properties
With oMessage
.To = mstrAddressTo
.From = mstrFrom
.Subject = mstrSubject
.Body = mstrMessage
.BodyFormat = menFormat
If Not mstrAddressToCc Is Nothing Then
.Cc = mstrAddressToCc
End If
If Not mstrAddressToBcc Is Nothing Then
.Bcc = mstrAddressToBcc
End If
If Not mcolAttachments Is Nothing Then
For Each strItem In mcolAttachments
oAttachment = New MailAttachment(strItem.ToString)
.Attachments.Add(oAttachment)
Next
oAttachment = Nothing
End If
End With
SmtpMail.SmtpServer = mstrMailServer
SmtpMail.Send(oMessage)
Catch ex As Exception
Throw ex
Finally
oMessage = Nothing
oAttachment = Nothing
mcolAttachments = Nothing
End Try
End Sub
-----------------------
I sincerely hope someone can help me…!
Thank you.
Ben
Ben [ benoit dot laflamme ( at ) ineedhits dot com ],
2004-03-09 20:07:28
#