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

Email PDF attachment using VB

Status
Not open for further replies.

GJParker

Programmer
Jul 4, 2002
1,614
GB
I have a program which emails pdf files out to users using Outlook

The problem is the pdf file is not being attached to the email but is contained in the document boy as plain/text data i.e.

name="Customers Vol and Val Weekly (Week 38).pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Customers Vol and Val Weekly (Week 38).pdf"

JVBERi0xLjIKJeLjz9MKNjQgMCBvYmoKPDwKL0xpbmVhcml6ZWQKMQovTwo2NgovSApbCiAgICAg
ICA1NTUKICAgICAgIDE4MwpdCi9MCiAgICAzMjI0NDcKL0UKICAgIDMxMTAxNwovTgoyCi9UCiAg
ICAzMjExMjMKPj4KZW5kb2JqCnhyZWYKNjQKMTMKMDAwMDAwMDAxNSAwMDAwMCBuDQowMDAwMDAw
NDg4IDAwMDAwIG4NCjAwMDAwMDA3MzggMDAwMDAgbg0KMDAwMDAwMDk1NiAwMDAwMCBuDQowMDAw
MDAxMTI0IDAwMDAwIG4NCjAwMDAwMDIyMzMgMDAwMDAgbg0KMDAwMDAwMjQ4MCAwMDAwMCBuDQow
MDAwMDAyNjQzIDAwMDAwIG4NCjAwMDAwMDM3NTAgMDAwMDAgbg0KMDAwMDAwMzk5MiAwMDAwMCBu
DQowMDAwMDA3Mzc0IDAwMDAwIG4NCjAwMDAxNTcwNDkgMDAwMDAgbg0KMDAwMDAwMDU1NSAwMDAw

if I email the same pdf document manually the file is attached correctly.

My Code is

Public objOutlook As Outlook.Application
Public objOutlookEmail As Outlook.MailItem
Public objOutlookAttachments As Outlook.Attachments

Public Sub SendEmail(ByVal strAttachment As String, strEmailTo As String, strSubject As String, strBody As String)

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookEmail = objOutlook.CreateItem(olMailItem)
objOutlookEmail.Subject = strSubject
objOutlookEmail.Body = strBody
objOutlookEmail.To = strEmailTo
Set objOutlookAttachments = objOutlookEmail.Attachments
If strAttachment <> &quot;&quot; Then
objOutlookAttachments.Add strAttachment
End If

objOutlookEmail.Send

Set objOutlook = Nothing
Set objOutlookEmail = Nothing
Set objOutlookAttachments = Nothing

End Sub

Any Suggestions would be greatl appreciated Gary Parker
Systems Support Analyst
 
I tried your code and it worked for me. May try to force the attachment type in the add statement:

objOutlookAttachments.Add strAttachment, olByValue ' = 1

Mark
 
tried your suggestion mark and this time the attachment isn't attached at all.

My original code works fine if the email is sent internally within the company my problem only occurs if i send external emails i.e msn, btinternet etc. but if i send to these external addresses manually it works fine.

Gary Parker
Systems Support Analyst
 

If your email client (and I assume Outlook) is set to send email formated in Rich Text Format (RTF) it may send in Transport Neutral Encapsulation Format (TNEF). A TNEF-encoded message contains a plain text version of the message, and a binary attachment that &quot;packages&quot; various other parts of the original message.

In addition to the receiving client, it is not uncommon for a mail server to strip out TNEF information from mail messages as it delivers them. If a server option to remove TNEF is turned on, clients will always receive a plain text version of the message. Microsoft Exchange Server is an example of a mail server application that has the option to remove TNEF from messages.

Try changing your default mail format to Plain Text to help ensure that TNEF is not sent unless an Outlook feature needs it.



Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top