Problem emailing PDF document from .net service

  • Thread starter Thread starter Sai Vajja
  • Start date Start date
S

Sai Vajja

Hi

I am trying to send a .pdf document as an email attachment using net.mail.
This email is being sent by a windows service application. After i receive
the email, and when i try to open the attachment, i get the following error
message...

"adobe reader could not open <filename> becuase it is either not a
suppported file type or because the file has been damaged(for example, it was
sent as an email attachment and wasn't correctly decoded)"

Here is a glimpse of the code doing the emailing..

Dim Mail_Message As MailMessage = New MailMessage(objEmail.MailFrom,
objEmail.MailTo)
Dim Server_Name As SmtpClient = New SmtpClient(MailServer)
Dim Port_Number As Int32 = Convert.ToInt32(MailServerPortNumber)

With Mail_Message
.Body = Trim(objEmail.Message)
.Subject = Trim(objEmail.Subject)
.Priority = objEmail.Priority
.IsBodyHtml = True
.BodyEncoding = System.Text.Encoding.Unicode

For Each oAttachment As Attachment In objEmail.Attachments
.Attachments.Add(oAttachment) 'Here is where i am
attaching the file
Next

End With
Server_Name.Send(Mail_Message)
 
Are you also generating the PDF file in your program? Is this segment being
triggered by a filesystemwatcher?

It's possible that you're attempting to send the PDF before it has been
fully generated. Verify this by comparing the version that you've received
in your inbox and with the version of the file that you're trying to send in
a hex reader. My bet is that there are some critical bits in the latter part
of the PDF that are missing from the version that was emailed.

If this is indeed the problem, the solution here is simply to wait until the
file is done being written to. Try using the System.IO library to open the
file exclusively. If you can't, then the file isn't ready. Wait a few
milliseconds and try again until the PDF is done.

Cheers,

-M
 
Back
Top