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 that with Outlook or other mail clients like Thunderbird & Co 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:
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.
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)
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.
Send generated PDF via email with Thunderbird Mail, or other standard mail application
Instead of Outlook, you can also configure 7-PDF Printer to send the generated PDF as an attachment directly to the mail application "Thunderbird Mail". To do this, you must set the "default app" for e-mail to Thunderbird under Windows and set a setting in a configuration file.
First select and set Thunderbird (or any other mail client) under Windows via "Settings" -> "Default apps"....
Using the 7-PDF Printer Options dialog we then create a global new options set, which is saved by default as
C:\ProgramData\PDF Writer\7-PDF Printer\Option Sets. As name for the new INI configuration file we choose "Thunderbird_Mail.ini".
We create the options set for all users... So select "Yes" or "Yes"...
With the text editor Notepad++ we now open this new INI configuration file. We change then into the line 135 and set
email=yes, and add under it still another new setting
emailclienttype=mapi64 completely. After that we save this configuration file.
The following screenshot shows the exemplary adjustment with Notepad++ again clearly:
Now we can directly send a print to 7-PDF Printer and in the print dialog select the previously created options set "Thunderbird_Mail" and thus send the created PDF to Thunderbird.
After PDF printing, Thunderbird Mail will open automatically and an eMail window will list the previously created PDF as a file attachment.
Note: You can use the above steps also for other eMail programs. You just need to know if your mail client is a 32 bit or 64 bit program and make the appropriate MAPI selection accordingly. For the Thunderbird used here we used
mapi64 because it is a 64 bit program, so for a 32 bit client we would have to choose
emailclienttype=mapi32. That's all!
Further information: If we had not created the option set globally for all, but only for the currently active user, the location of the new configuration file would be under:
C:\Users\[CURRENT ACTIVE USER]\AppData\Roaming\PDF Writer\7-PDF Printer\Option Sets!
Starting from line 135 they see also still further
firstname.lastname@example.org automatically a "to send to" - EMail specify over the configuration file. More mail configuration options can be found under Settings on this page!
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.
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.