Solved

VBS ObjEmail Attach PDF - Gives error when opening attachment

Posted on 2009-05-13
3
1,167 Views
Last Modified: 2012-06-21
I have a vb script that sends an email to a user and attaches a PDF document, but when the user opens the PDF the following errors occur:

Adobe Reader: An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.

Adobe Reader: Cannot extract the embedded font 'QVFRVI+ArialMT'. Some characters may not be displayed or print correctly.

After the errors, all pages in the PDF are blank. The funny thing is I can view the PDF on the server and I can copy the PDF and manually move it to the users machine and it will open fine. We only receive these errors when is is sent in this script. Any ideas? Thanks.
Set CurrentUser = BOServer.MOContainer("Current User").Open("").DataObject

Set objEmail = CreateObject("CDO.Message")

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "exchange.com"

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 27

objEmail.Configuration.Fields.Update

objEmail.From = CurrentUser.MWUser.Email

objEmail.To = ""

objEmail.AddAttachment "file://D:\Appraisals\"& Loanapp.LoanNumber &".pdf"
 

' Check For Processor Email Address

if not safeeval("LoanApp.Processor.Email") = "" then

   objEmail.To = LoanApp.Processor.EMail

end if

'Set Subject line

objEmail.Subject = "Decision status changed to " & FieldValue & " on Loan " & LoanApp.AppNum

'Send Message

if objEmail.To <> "" then

   objEmail.Send

end if

Set objEmail = nothing

Result = False

Open in new window

0
Comment
Question by:asmyatt
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 24383640
1/ here's how I have used a script to attach file. note that I use the std drive path etc as file:\\ is the default attachment type.

so the method of attaching and giving the attachment a name is a little different.
this is derived from MSDN example... http://msdn.microsoft.com/en-us/library/ms526983.aspx

2/ But how is the PDF being created ?  The fact that you can open it on the server may be just because the server has the correct fonts, and fonts are NOT being embedded in the PDF, or embeded incorrectly.  I think that is an option of the PDF create process.
2.1/ what happens if you copy the PDF file from server to a  USB disk   and try to open on a workstation ?

this will test if it is a mail problem or a pdf problem.

       If Not fso.FileExists(savePath) Then

                LogIt "4.4.1 Attachment not found <" & savePath & ">"

                Exit Do

       End If

       Set objAttachment = objMessage.AddAttachment(savePath)

                            

       'Once you 've got the bodypart, you can update the FileName attribute of the content-disposition header field thus:-

       Set msgFlds = objAttachment.Fields

       msgFlds("urn:schemas:mailheader:content-disposition") = "attachment; filename=""" & savefile & """"

       msgFlds.Update
 

       objMessage.Fields.Update

       objMessage.DataSource.Save

Open in new window

0
 
LVL 2

Author Comment

by:asmyatt
ID: 24385924
I still get the same results, but I narrowed it down. When I enter values for the To:, From:, Subject, etc and save the script on the server, it runs fine and the attachment is fine. We have a vb script engine inside our application and when i run it inside the application, we cannot view the attachment. I've decided to seperate this into two scripts. The one in the application will save the values from the db in a txt file and execute the email script on the server.  The email script will first grab the values from the txt file and use it for the To:, Attachment and Subject.

So my question is on the email script, how can I make it grab the values from the txt file and store it as a variable (variables below would be emailaddress and loannumber). I would then use the variables for the To:, Attachment and Subject. See below.
dim emailaddress

dim loannumber
 

Set objEmail = CreateObject("CDO.Message")

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "exchange.com"

objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 27

objEmail.Configuration.Fields.Update

objEmail.From = "centralemail@123.com"

objEmail.To = emailaddress

objEmail.AddAttachment "file://D:\Appraisals\"& loannumber &".pdf"

'Set Subject line

objEmail.Subject = "Decision status changed to " & FieldValue & " on Loan " & loannumber

'Send Message

if objEmail.To <> "" then

   objEmail.Send

end if

Set objEmail = nothing

Open in new window

0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 24391020
read a text file.....


   ' Read a Comma Separated Values file' 

    Const ForReading = 1

    

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objtextFile = objFSO.OpenTextFile(sFileInp , ForReading)

    

    Do While objtextFile.AtEndOfStream <> True

      strline = objtextFile.ReadLine

      If InStr(strline, ",") Then    'found some values'

        arrrecord = Split(strline, ",")    'split into array elements'

        if ubound(arrrecord)=4 then  

            'looks like a fullrecord'

           i = i + 1

           sName = arrrecord(1)

           sAddress = arrrecord(2)

           lLoanNumber = arrRecord(3)

           iFieldValue = arrRecord(4)
 
 

           'create new message'

           SendMail sName, sAddress, lLoanNumber, iFieldValue

 

        End If

      End If

    Loop

    objtextFile.Close   

    Set objtextFile  = Nothing

    Set objFSO = Nothing
 

Wscript.Echo "Sent " & i & " update messages"
 

Wscript.quit

'--------------------------------------------------------------'

Sub SendMail(sName, emailaddress, LoanNumber,FieldValue )

     Dim objEmail

     

    Set objEmail = CreateObject("CDO.Message")
 

    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "exchange.com"

    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 27

    objEmail.Configuration.Fields.Update

    objEmail.From = "centralemail@123.com"

    objEmail.To = emailaddress

    objEmail.AddAttachment "file://D:\Appraisals\"& loannumber &".pdf"

    'Set Subject line'

    objEmail.Subject = "Decision status changed to " & FieldValue & " on Loan " & loannumber

    'Send Message'

    if objEmail.To <> "" then

      objEmail.Send

    end if

    Set objEmail = nothing
 

End Sub

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now