Link to home
Start Free TrialLog in
Avatar of asmyatt
asmyatt

asked on

VBS ObjEmail Attach PDF - Gives error when opening attachment

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

ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

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
Avatar of asmyatt
asmyatt

ASKER

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

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