[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SMTP and application/pdf Content-Type

Posted on 2005-05-11
4
Medium Priority
?
607 Views
Last Modified: 2010-05-01
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)
0
Comment
Question by:beckercd
  • 2
4 Comments
 
LVL 22

Expert Comment

by:JesterToo
ID: 13981201
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
 

Author Comment

by:beckercd
ID: 13981562
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
 
LVL 13

Accepted Solution

by:
softplus earned 1500 total points
ID: 13984220
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
 

Author Comment

by:beckercd
ID: 13985775
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question