Solved

VBS ObjEmail Attach PDF - Gives error when opening attachment

Posted on 2009-05-13
3
1,176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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