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"
' Instanciate the .Net Framework used for sending e-mails
oMessage = New MailMessage
' Sets all relevant properties
.To = mstrAddressTo
.From = mstrFrom
.Subject = mstrSubject
.Body = mstrMessage
.BodyFormat = menFormat
If Not mstrAddressToCc Is Nothing Then
.Cc = mstrAddressToCc
If Not mstrAddressToBcc Is Nothing Then
.Bcc = mstrAddressToBcc
If Not mcolAttachments Is Nothing Then
For Each strItem In mcolAttachments
oAttachment = New MailAttachment(strItem.ToString)
oAttachment = Nothing
SmtpMail.SmtpServer = mstrMailServer
Catch ex As Exception
oMessage = Nothing
oAttachment = Nothing
mcolAttachments = Nothing
I sincerely hope someone can help me…!
Ben [ benoit dot laflamme ( at ) ineedhits dot com ],