Custom Delivery Methods
A custom delivery method can be created in Python.
Your script will be called with a single parameter - the path to a JSON file that contains all of the information about the delivery.
JSON Content
The content of the file will look like this…
{ "files": [ [ ".../Test Report (2024-12-08).pdf", "Optrix Test Reports (2024-12-08).pdf" ] ], "options": { "sitename": "Site Name", "sitecode": "", "timezone": "Australia\/Sydney", "server": "localhost", ... "apikey": "myserverapikeyishere", "title": "Test Report", "bundle": "testing", "reporturl": "http://myserver/s/op/reportlist/", "bundleurl": "http://mysite/s/op/reportlist/?folder=:testing" }, "destinations": [ { "name": "Daily", "skip": [], "contentcode": "full", "path": ".../Test Report (2024-12-08).pdf", "style": "sharepoint", "attachments": [ [ "..../Test Report (2024-12-08).pdf", "Optrix Test Report (2024-12-08).pdf" ] ] } ] }
The Destinations section will include each of the named destinations from the reporting system. Each of those also include an array of 'attachments', containing the full path (trimmed in the example above) and the target file-name of each of the files to be transmitted.
The Options section gives access to any of the user-configured settings, plus some details about the transmission as a whole (such as the title of the email, HTML link back to the report system etc.).
Example Code
You'll find a basic framework for a delivery method below…
import datetime import os import json #Import any libraries you need here #Load the details of the delivery f = open(sys.argv[1]) content = f.read() f.close() details = json.loads(content) #Hard-code any keys, or read them from the global reporting options... apikey = details['options']['apikey'] #TODO: Add Connection Code failures = None #Go through each destination (there's usually only one, but it's possible to have more). for d in details['destinations']: #For each attachment to be sent to the destination... for f in d['attachments']: try: #TODO: Add Delivery Code pass except: #Note down the reason the failures happened failures = "Failed!" #Return the status of the task if failures is None: print('----') print('SUCCESS') else: print('----') print('FAILURE: ' + failures)
Basically, you'll need to fill in the two 'TODO' sections - connecting to the destination and transmitting the individual files.