E
Eric Guthmann
We're running into an intermittent problem with the
System.Net.Mail.SmtpClient class in the .NET 2.0 Framework when working with
PDF attachments (it may be any attachment, but we're working with PDF
files). About 10% of the emails sent via this class are missing their
attachment. We have verified everything on our side prior to the handoff to
the SmtpClient.Send method, and have even tried resending those emails that
are received with no attachment and it subsequently works fine.
Has anyone else seen this issue, and if so, is there a workaround?
Dim ms As New MemoryStream
'' ....
'' Generate PDF document into the memory stream
'' ....
ms.Seek(0, SeekOrigin.Begin)
Dim mailAttachment As New Attachment(ms, "Attachment.pdf",
"application/pdf")
Dim msg As New MailMessage
msg.From = New MailAddress(emailFromAddress, emailFromName)
msg.Subject = subject
msg.To.Add(toAddress)
msg.Bcc.Add(bccAddress)
msg.Attachments.Add(mailAttachment)
Dim smtp As New SmtpClient(emailSmtpServer, emailSmtpPort)
Try
smtp.Send(msg)
Finally
'' we have also tried without the following dispose calls, but this did
not change the result
msg.Dispose()
mailAttachment.Dispose()
End Try
Here are the specifics:
1. The code is in a Windows Service running under the Network Service
account
2. It doesn't look like it has anything to do with the actual attachment
because emails that are missing the attachment can be resent without problem
3. We're communicating with an Exchange 2000 server
4. We have added code to verify that the PDF was actually generated and is
well-formed. Everything looks good until the SmtpClient.Send call. It is
in this call that the attachment is sometimes lost.
5. The loss of attachments seem to occur most when the system is under some
load.
System.Net.Mail.SmtpClient class in the .NET 2.0 Framework when working with
PDF attachments (it may be any attachment, but we're working with PDF
files). About 10% of the emails sent via this class are missing their
attachment. We have verified everything on our side prior to the handoff to
the SmtpClient.Send method, and have even tried resending those emails that
are received with no attachment and it subsequently works fine.
Has anyone else seen this issue, and if so, is there a workaround?
Dim ms As New MemoryStream
'' ....
'' Generate PDF document into the memory stream
'' ....
ms.Seek(0, SeekOrigin.Begin)
Dim mailAttachment As New Attachment(ms, "Attachment.pdf",
"application/pdf")
Dim msg As New MailMessage
msg.From = New MailAddress(emailFromAddress, emailFromName)
msg.Subject = subject
msg.To.Add(toAddress)
msg.Bcc.Add(bccAddress)
msg.Attachments.Add(mailAttachment)
Dim smtp As New SmtpClient(emailSmtpServer, emailSmtpPort)
Try
smtp.Send(msg)
Finally
'' we have also tried without the following dispose calls, but this did
not change the result
msg.Dispose()
mailAttachment.Dispose()
End Try
Here are the specifics:
1. The code is in a Windows Service running under the Network Service
account
2. It doesn't look like it has anything to do with the actual attachment
because emails that are missing the attachment can be resent without problem
3. We're communicating with an Exchange 2000 server
4. We have added code to verify that the PDF was actually generated and is
well-formed. Everything looks good until the SmtpClient.Send call. It is
in this call that the attachment is sometimes lost.
5. The loss of attachments seem to occur most when the system is under some
load.