SMTP and application/pdf Content-Type

I am trying to send an email with a PDF attachment using SMTP calls.  I have successfully done this sending text file attachments but now I need to send a PDF file attachment.  Below is the piece of the code I am having trouble with.  I think I am missing something but not sure what.  Any help is appreciated.  Thank you.

sSend = ""
sSend = sSend & "From: Me" & Chr(13) & Chr(10)
sSend = sSend & "To: " & SendTo & Chr(13) & Chr(10)
sSend = sSend & "Subject: " & Subject & Chr(13) & Chr(10)
sSend = sSend & "MIME-Version: 1.0" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: multipart/mixed;" & Chr(13) & Chr(10)
sSend = sSend & " boundary=testboundry" & Chr(13) & Chr(10)
sSend = sSend & Chr(13) & Chr(10)
sSend = sSend & "--testboundry" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: text/html" & Chr(13) & Chr(10)
sSend = sSend & Chr(13) & Chr(10)
sSend = sSend & Message & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sSend = sSend & "--testboundry" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: application/pdf; name=""Test.pdf"";" & Chr(13) & Chr(10)
sSend = sSend & "Content-Transfer-Encoding: base64;" & Chr(13) & Chr(10)
sSend = sSend & "Content-Disposition: attachment; filename=""Test.pdf"";" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sSend = sSend & "--testboundry--"
sSend = sSend & Chr(13) & Chr(10) & "." & Chr(13) & Chr(10)
beckercdAsked:
Who is Participating?
 
softplusCommented:
This is not quite so simple. You need to encode the file using something (you can't send binary data via email directly, you must "change" it into text and then "change" it back when you recieve it; that's what the encodings are for); you have "Content-Transfer-Encoding: base64", you could use that.
You can use something like this: http://www.aspsimply.com/vb/MIMECode.aspx (among lots of others ...)
You would then add:
sSend = sSend & B64EncodeFileToMail( NameOfPdfFile )
just above your last --testboundry--

Alternately, you could go with any of the 3rd party mail-objects available, most of them do all of this for you :)
0
 
JesterTooCommented:
Try this modified version to see if it solves the problem...

sSend = ""
sSend = sSend & "From: Me" & Chr(13) & Chr(10)
sSend = sSend & "To: " & SendTo & Chr(13) & Chr(10)
sSend = sSend & "Subject: " & Subject & Chr(13) & Chr(10)
sSend = sSend & "MIME-Version: 1.0" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: multipart/mixed;" & Chr(13) & Chr(10)
sSend = sSend & " boundary=testboundry" & Chr(13) & Chr(10)
sSend = sSend & Chr(13) & Chr(10)
sSend = sSend & "--testboundry" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: text/html" & Chr(13) & Chr(10)
sSend = sSend & Chr(13) & Chr(10)
sSend = sSend & Message & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sSend = sSend & "--testboundry" & Chr(13) & Chr(10)
sSend = sSend & "Content-Type: application/octet-stream" & Chr(13) & Chr(10)
sSend = sSend & "Content-Transfer-Encoding: base64" & Chr(13) & Chr(10)
sSend = sSend & "Content-Disposition: attachment;" & Chr(13) & Chr(10)
sSend = sSend & " filename=""Test.pdf"" & Chr(13) & Chr(10) & Chr(13) & Chr(10)
sSend = sSend & "--testboundry--"
sSend = sSend & Chr(13) & Chr(10) & "." & Chr(13) & Chr(10)
0
 
beckercdAuthor Commented:
Same results, I get a 64 byte file attachment which Acrobat Reader won't open.  I think I need to some how read the file but since it isn't a text file, I am not sure how that part should work.
0
 
beckercdAuthor Commented:
I am just going to change the file I am generating from a PDF file to an RTF so I can use my existing code that was working for text files.  I am out of time to research this anymore.  Thank you for all your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.