The following will show you how to attach the new PDF file to an email in Outlook. After the PDF is created, a new email is displayed and the PDF is attached.

In this example, we will use a very simple Visual Basic Script (VB Script) file that can be run from a command line.

    Option Explicit
    
    Dim fn
    Dim ol, ns, newMail
    Const olMailItem = 0
    
    Rem -- Check that there is the right number of arguments
    If WScript.Arguments.Count <> 1 Then 
            Msgbox "Wrong arguments"
            Wscript.Quit
    End If
    
    Rem -- Get the file name from the command line
    fn = WScript.Arguments.Item(0)
    
    Rem -- Get access to the Outlook application
    Set ol = WScript.CreateObject("Outlook.Application")
    Set ns = ol.getNamespace("MAPI")
    
    Rem -- Create the new mail
    Set newMail = ol.CreateItem(olMailItem)
    
    Rem -- Attach the file
    newMail.Attachments.Add fn
    
    Rem -- Display the new message
    newMail.Display
    
    Rem -- Clean up
    Set newMail = Nothing
    Set ns = Nothing
    Set ol = Nothing
    

Save the code to a script file named:

C:\Program Files\7-PDF\PDF Printer\EmailOnSuccess.vbs

Now you can make the printer run the script if the PDF was created successfully. Add the following two lines of code to a configuration file. In this example, we can place them in global.ini.

RunOnSuccess=cscript.exe "C:\Program Files\7-PDF\PDF Printer\EmailOnSuccess.vbs" "%1"
RunOnSuccessMode=Normal

This will run the script and pass the new PDF document as a parameter.

You can easily modify this script to delete the PDF after attaching it if you do not want it on your system after it is sent.

LiveZilla Live Chat Software
Top