True PDF Software
for you!

  • Deutsch
  • English

SMTP- / Mail Delivery of PDF Invoices via FAX directly out of SAP

For a company, 7-PDF Printer was configured as a network PDF writer that was used as PDF Invoice printer directly from a ERP SAP system.

After pdf creation the generated pdf-file is delivered to a FAX-Server for sending the PDF via FAX. For this, a user can put the fax-number to an input-field by 7-PDF Printer. After 7-PDF Printer has generated PDF and has the fax-number, it send all via SMTP to the fax-server.

The example code shows that complex process above. All this with some few lines of VBScript Code in conjunction with 7-PDF Printer. Enjoy!

  1. Dim global_success, faxnr, SMTPServer, Recipient, From, Subject, Message
  2.  
  3. Sub OnConfigLoaded()
  4.     Rem -- Modify the configuration to extract text from the printer
  5.     Rem -- output.
  6.    
  7.     faxnr = InputBox("Faxnummereingabe (ohne Sonder- und Leerzeichen):", "Rechnung senden")
  8.    
  9.    Context("Config")("showsettings") = "never"
  10.     Context("Config")("showpdf") = "no"   
  11.     Context("Config")("output") = "C:\temp\print\<date>-<time>.pdf"
  12.     Context("Config")("superimpose") = "C:\temp\print\background.pdf"
  13.     Context("Config")("author") = "<username>"
  14.     Context("Config")("confirmoverwrite") = "no"
  15.     Context("Config")("mergefile") = "C:\temp\print\agb.pdf"
  16.     Context("Config")("mergeposition") = "top"
  17.    
  18. End Sub
  19.  
  20. Sub OnSuccess()
  21.   global_success = true
  22. End Sub
  23.  
  24. Sub OnAfterPrint()
  25.    
  26.   If global_success Then
  27.    
  28.     Rem -- Absender <username>@mailserver.de
  29.     Rem -- Empfänger faxnr@fax.local
  30.    
  31.     SMTPServer = "smtp.mailserver.local"
  32.     Recipient = faxnr & "@fax.local"
  33.     From = Context("DocumentAuthor") & "@mailserver.de"
  34.     Subject = "Ihre SAP Rechnung"
  35.     Message = "Anbei erhalten Sie Ihre SAP - Rechnung fuer den
  36. Technikerauftrag des Technikers " & Context("DocumentAuthor")
  37. & vbcrlf & "Vielen Dank fuer Ihren Auftrag!"
  38.  
  39.     set msg = CreateObject("CDO.Message")
  40.     msg.From = From
  41.     msg.To = Recipient
  42.     msg.Subject = Subject
  43.     msg.TextBody = Message
  44.    
  45.     ' To add an attachment uncomment this line
  46.     msg.AddAttachment Context("OutputFileName")
  47.  
  48.     msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
  49.     msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  50.     msg.Configuration.Fields.Update
  51.  
  52.     msg.Send
  53.    
  54.     MsgBox "Die Rechnung wurde versendet."
  55.    
  56.     ' Del PDF
  57.     Set objFSO = CreateObject("Scripting.FileSystemObject")
  58.     objFSO.DeleteFile(Context("OutputFileName"))
  59.    
  60.   Else
  61.    
  62.     MsgBox "Ein Fehler beim Rechnungsversand ist aufgetreten. Bitte versuchen Sie es erneut!"
  63.    
  64.   End If
  65.  
  66. End Sub

Download Example File

You can download and run the example yourself. The files needed are available here. The VBS file must be placed in the macros sub folder of the PDF writer installation. You can use the MacroDir setting to change the location of the VBS files if needed.

AttachmentSize
Package icon Example files1.1 KB