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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing with PDF attachment problem

Status
Not open for further replies.

redheadpgr

Programmer
Feb 8, 2002
17
0
0
US
I'm using VB.NET with the following code to attach a PDF file to an email message:

Dim myMessage As New MailMessage

myMessage.From = "me@mycompany.com"
myMessage.To = "someone@anothercompany.com"
myMessage.Subject = "Monthly Report"
myMessage.Attachments.Add(New MailAttachment("c:\myfolder\ExportFile.pdf"))

SmtpMail.SmtpServer = "my_smtpserver"
SmtpMail.Send(myMessage)

Of course, at the top of the form I add the following:

Imports System.Web.Mail

The PDF file is created on a previous screen in my application.

The problem appears to be that the PDF file gets corrupted when it gets attached and sent. I've looked at the created file on the drive and it is okay.

Any clues would be very helpful.
 
red --

Just a thought, not being familiar with emailing pdf files. It might be that you have to specify the Base64 MailEncoding enumeration (encoding the attachment). Try:
Code:
myMessage.Attachments.Add(New MailAttachment("c:\myfolder\ExportFile.pdf", MailEncoding.Base64))

..just a thought as I'm not familiar with what pdf requires. Everything else seems to be on target.
 
Thanks, Isadore.

I tried doing that but it still sent corrupt files. You did, however, send me in the right direction. What finally worked was:

Code:
myMessage.Attachments.Add(New MailAttachment("c:\myfolder\ExportFile.pdf", MailEncoding.UUEncode))

Thanks for your help.
 
red: Can you believe it!

There was only 2 choices. UUEncode and Base64. I saw a reference using pdf and they chose Base64 so I put my money on that. I think there's a lesson here (guessing will bring up the wrong answer 50% of the time). I'm glad it worked for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top