Send PDF automatically by email / PDF Printer
After creating a PDF file, the PDF Printer can be set up so that it automatically sends this PDF file with Outlook, an Exchange server or via an IMAP server via email. We want to show you how it works here. Next below you will also find a description of how to send PDF files directly by email, because from version 12 these setting options are also available for you.
But let's first come to the possibilities of working with VBScript instead of directly. We want to show you how this works here. For this we use the built-in VBScript event handler of our printer and the MAPI Api to address Outlook. As an example, you can also coordinate an Exchange Server or an IMAP Server (see download example at the bottom), as mentioned by adjusting a few lines of code! The example shown is intended to support you in realizing this automation.
Please note that this example requires licensing of the Professional Edition, i.e. a license.xml file Professional, because the Event Handler can only be used from the Professional Edition.
In our example, we configure our PDF printer in the tab "E-Mail" in the Options dialog window, and we already give the PDF printer the recipient's email address, subject and body text. For breaks in body text, we use HTML code and the well-known <br> HTML Tag. Instead of specifying this information fix, you could also read it dynamically from the Active Directory via VBScript and LDAP. This is also possible with a few lines of code. Basically, you can tap into any data source and then integrate it into the process in the VBScript coding, which is listed below, and thus act even more flexibly. For our example, we will limit ourselves to a fixed configuration that is stored in the PDF printer.
Illustration: Fixed mail configuration of recipient, subject and text.
Next we come to the event handler of the PDF printer. We can tap this using a small macro script in VBScript. We put the macro in the Macros folder of the PDF printer. This is always in the installation path of the PDF printer. So mostly under:
C:\Program Files\7-PDF\PDF Printer\Macros
Illustration: We save the VBScript code in the Macros folder as mapi.vbs
We come to the actual code of our example, which we have saved in the Macros directory in the VBS file mapi.vbs as shown in the screenshot above.
Dim global_success Sub OnSuccess() global_success = true End Sub Sub OnAfterPrint() If global_success Then Rem -- Get the file name from the command line fn = Context("OutputFileName") Rem -- Get access to the Outlook application Set ol = CreateObject("Outlook.Application") Set ns = ol.getNamespace("MAPI") Rem -- Create the new mail Set newMail = ol.CreateItem(olMailItem) Rem -- Build eMail and attach the pdf file newMail.To = Context("Config")("emailto") newMail.Subject = Context("OutputFileName") + " " + Context("Config")("emailsubject") newMail.HTMLBody = Context("Config")("emailbody") newMail.Attachments.Add fn Rem -- Display the new message newMail.Display Rem -- Del PDF Rem -- Set objFSO = CreateObject("Scripting.FileSystemObject") Rem -- objFSO.DeleteFile(Context("OutputFileName")) Else MsgBox "An error has occurred. Please try again!" End If End Sub
What does the script do? In the coding we see two events of the PDF printer, OnSuccess()
and OnAfterPrint()
. If PDF creation is successful, a global variable global_success is set to TRUE in OnSuccess ()
.
This is reacted to in OnAfterPrint()
and, if successful, the MAPI from Outlook is addressed. From the configuration of the PDF printer, the fixed mail recipient, subject and body text are determined and the MAPI is filled by Outlook. As an attachment, the file handle fn is placed on the PDF file previously created by the PDF printer and attached to the email. Finally, the email is automatically called up in Outlook. Instead of newMail.Display
one could have carried out the automatic sending with newMail.Send
. The commented out lower lines of VBScript code would delete the PDF file previously created by the PDF printer.
As already mentioned, the example shown above should only provide an introduction for you and illustrate the possibilities of our PDF printer. With a few lines of code, you can use the PDF printer most effectively and automate many processes related to PDF generation. And you don't need any additional tools, just our PDF printer.
Optimize Your Printing Processes with the 7-PDF Mailer Plug-In
By integrating the 7-PDF Mailer Plug-In into your 7-PDF Printer, new opportunities for controlling your printing processes arise. This plug-in enables seamless integration of external commands (control codes) to precisely manage your printing operations. Once the plug-in is linked to an instance of your 7-PDF Printer, you can incorporate these control codes into your print jobs. These codes can be inserted directly into the print text or print forms originating from systems like ERP, CRM, or WaWi. With just a few simple control codes, you can, for example, send print jobs directly via email, allowing you to customize the email text and much more. A comprehensive overview of all available control codes, including @@to
, can be found in the subsequent documentation.
Send PDF directly as email via SMTP
From version 12, our PDF printer offers setting options with which generated PDF files can be sent directly via SMTP! You can find the setting options for this here. The difference to the options listed above is that you can do without VBScript entirely. You could also use the new settings to change the SMTP server at runtime in a VBScript. The settings can also only be fixed in the configuration files (INI files) of the PDF printer. This possibility is also to be emphasized when installing a PDF network printer instance for direct sending of generated PDF files as email!
As a customer, you decide which of the options listed here is right for you. The PDF printer offers at least the right configuration options for PDF printing and subsequent sending by email for every application.
Determine email from print data and email automatically
We would like to show you with our example VBScript Macro "pdfmailer.vbs" shown here, how you can send an automatic invoice print from e.g. an ERP system directly to recipients by email, and the necessary email address of the invoice recipient is obtained from the print data.
Send PDF with Outlook if "required" by the user
You can find them on this page an example of how to send a generated PDF directly with a small VBScript program. It's similar to the approach described here but doesn't work as a macro. An execution can not only be configured globally, but also individually. I.e. that a user can control by specifically executing the VBScript program when he wants to transfer a generated PDF to Outlook and send it with it.
Example file download
You can download the sample code (mapi-outlook.zip) here. Furthermore, we have provided an example (send-mail-via-googlemail.vbs.zip) for download, which shows how you can use the Gmail IMAP server to send PDF files instead of Outlook. Make sure that you copy the VBS file that suits you into the Macros folder of the PDF printer as shown above!
Downloads
Attachment | Size |
---|---|
Download code example (mapi-outlook.zip) | 1.00 KB |
Download code example (send-mail-via-googlemail.vbs.zip) | 1.00 KB |