Link to home
Start Free TrialLog in
Avatar of beckercd
beckercd

asked on

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)
Avatar of JesterToo
JesterToo
Flag of United States of America image

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)
Avatar of beckercd
beckercd

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of softplus
softplus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.