Solved

VBS ObjEmail Attach PDF - Gives error when opening attachment

Posted on 2009-05-13
3
1,168 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

13 Experts available now in Live!

Get 1:1 Help Now