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.

You can find more examples on this topic here.... The difference here is that the other examples automatically send or at least prepare an e-mail for each PDF print. In the example below, there is also the option of only triggering a mailing if the user wants to.

Send generated PDF by e-mail with Outlook (for users)

The PDF printer offers the possibility to start Outlook after successful PDF creation and automatically attach the PDF to a new email by setting a "check mark" in the print dialog or as a default value in the options dialog of the 7-PDF Printer. The prerequisite for this is of course that you use Outlook 365 or older on your system as an e-mail application.

You can access the options dialog in Windows 10 via the Windows 10 search...just type 7-PDF Printer Options into the search field....

After starting a PDF print from an application such as Word (via menu item File -> Print... -> 7-PDF Printer") the print dialog of our printer appears as shown in the following figure:

Print dialog of 7-PDF Printer shows checkmark set by user at setting E-mail
Print dialog of 7-PDF Printer shows checkmark set by user at setting Email

The user now decides to transfer the PDF to be created directly to Outlook by checking the Email checkbox. After the PDF creation, Outlook or a new e-mail opens automatically with the just created PDF file as an attachment. The previously created PDF file is of course in the selected storage location of the user.

An Outlook e-mail with PDF file attached to the mail
An Outlook e-mail with PDF file attached to the mail

In the options dialog of the 7-PDF printer, you can also set this checkmark (tab "General") or transfer additional information to an Outlook e-mail. The tab for this is "E-Mail". For example, you can specify an e-mail address, a subject or a message text (HTML) which is then transferred to the generated Outlook e-mail (MAPI). The following screenshot shows the default values we have defined. Do not forget to save! Translated with www.DeepL.com/Translator (free version)

The 'E-mail' tab with predefined values
The tab/tab "E-Mail" with predefined values

Now we start again a test print from Microsoft Word 365 via 7-PDF Printer to create a PDF, because we want to check if a new Outlook email opens automatically with the PDF and the previously specified values. Let's go...after we have sent a print job to 7-PDF Printer via "Print", the print dialog of 7-PDF Printer should open automatically, we check the settings and "Save" the PDF.

Perfect...Since we left the check mark in the print dialog for "Open PDF after creation", Acrobat Reader opens with the new PDF created from Microsoft Word and a moment later a new Outlook e-mail with PDF file attachment is also automatically displayed. Great, the fixed values from the "Email" tab from the 7-PDF Printer Options dialog were also applied right away.

Outlook email with PDF file attachment opens automatically
Outlook email with PDF file attachment opens automatically

Sending mail with VBScript and Outlook (for Experts)

In contrast to our first possibility described above, you can also initiate a mail dispatch with Outlook via VBScript. The advantage here is that you as a programmer can influence the mail dispatch. So for example you can get more data from databases or LDAP to control the mail dispatch dynamically. The example shown here does not go so far, but gives programmers an introduction to the possibilities that 7-PDF Printer offers!

    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

Important: Please do NOT copy this script into the Macros folder of the PDF printer, otherwise the execution will not work! 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. Important: You must set the AllowExecute setting to 1 in the registry so that the execution of the VBScript macro is not acknowledged by a runtime error. You can find more about AllowExecute and how to activate it here...

Do not run globally but as a user, if "necessary"...

If you put it in the global.ini as described above, this configuration is globally valid. EmailOnSuccess.vbs would then be executed for every PDF print. In addition, the configuration via a global.ini requires the registry setting AllowExecute to be set, or it is absolutely necessary here. If you do not want that, you can only configure an execution of EmailOnSuccess.vbs via the 7-PDF Printer Options Dialog if "required". To do this, you simply create an Option Set called "Send to Outlook", and for this new Option Set you then save cscript.exe and the VBScript EmailOnSuccess.vbs in the "Run" tab. Also !cscript.exe "C:\Program Files\7-PDF\PDF Printer\EmailOnSuccess.vbs" "%1"

You can call up the options dialog under Windows 10 via the Windows 10 search...just type 7-PDF Printer Options in the search field...

Activate ShellScript mode

If you want to avoid a DOS box being displayed for a short time, activate the ShellScript mode with a preceding exclamation mark and set the mode to hidden, so:

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

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.

Further examples

We are pushing the topic further in this more extensive example and are using Outlook MAPI directly with 7-PDF Printer. We also show how you could use an Exchange Server or an external IMAP service such as Googlemail to send mail with a 7-PDF printer. The examples listed should provide you with the basis for your own solution approaches.

Top