Integrate with Port25′s PowerMTA SMTP Server’s Monitoring Interface Via HTTP

March 16th, 2012 by Mark Lewis

Port25′s PowerMTA SMTP Server

PowerMTA is a high performance SMTP server used by many email marketing technology companies.  Not only does the server handle high volume of outgoing email, the server also provides various means of integration for email submission, data merging, and monitoring.

The server provides a monitoring interface over HTTP.  Server administrators can log into a web interface to see the current activity on the server.  This web interface can also send information marked up as XML.  Having integrated PowerMTA into various projects, Mass Transmit has built some PHP classes to assist with integrating with the monitoring interface.

PowerMTA configuration

You must enable the HTTP management interface and authorize the IPs to connect to it. Please refer to the PowerMTA™ v4.0 User’s Guide.

PowerMTA class

For detailed information on the data provided by the monitoring interface, please consult the PowerMTA™ v4.0 User’s Guide.

setOption(array|string $option, int|string $value = null) : null

Set a specific option prior to retrieving data.  Multiple name/value pairs can be specified by passing an associative array or repeated calling this method.  Many methods which retrieve data can be passed options as an associative array.

status() : string

Retrieves the status data in XML format.

queues(array $options = null) : string

Retrieves the queues data in XML format.  You can set the following options as an associative array of arguments or by calling the setOption() array.

  • queue: [string] wildcard search. format: domain/queue
  • sort: [string] field to sort by (name|rcpt|size)
  • connected: [string] connected? (yes|no|both)
  • paused: [string] paused? (yes|no|both)
  • mode: [string] mode (normal|backoff|both)
  • maxItems: [int] maximum number of items to display
  • refresh: [int] n/a

queueDetail(string $queue) : string

Retrieves data for a specific queue in XML format.  $queue is specified as domain/queue.

domains(array $options = null) : string

Retrieves the domains data in XML format.

  • domain: [string] wildcard search for domain
  • vmta: [string] widcard search for virtual MTA
  • sort: [string] field to sort by (name|rcpt|size)
  • connected: [string] connected? (yes|no|both)
  • maxItems: [int] maximum number of items to display
  • refresh: [int] n/a

domainDetail(string $domain) : string

Retrieves data for a specific domain in XML format.

vmtas() : string

Retrieves data for the virtual MTAs in XML format.

jobs() : string

Retrieves data for the jobs in XML format.

logs() : string

Retrieves data for the log files in XML format.

getFile($file) : string|boolean

Retrieve the specified log file.  If $file is an accounting CSV file, it is passed to the Parse_Csv object for parsing.

getCsv() : Parse_Csv

Get the Parse_Csv object parsing the downloaded accounting log file.

deleteFile() : null

Delete the file on the localhost that was retrieved using getFile().

Parse_Csv class

There is an instance of the Parse_Csv object contained within the PowerMta object to parse any downloaded accounting log files.  After successfully calling PowerMta::getFile() to download an accounting, the file is passed to the Parse_Csv object for parsing.  When parsing a CSV file,the object will pass an array containing the values of the cells of any line matching the filter settings to a specified callback function.

setLineCallback(array|string $callback) : void

Specify a callback function (string) or an object’s  method (array) to pass the row from the CSV file matching the filter criteria.  The callback function will receive an array which is the fields of the row in order, left to right.

addFilter($key, $value) : void

Add a filter for the parser.  Rows matching the filters will be sent to the callback function/method as an array.  $key is either the numeric index for that columns or its ame from the header row.  $value is either an exact match or a regular expression (delimited by /../).  If $value is an array, the values will be OR’d for that key.  Multiple $key criteria will be AND’d together.  Multiple calls to addFilter() for the same will will also be AND’d together.  Specifying $key as * will apply that $value to all the fields.

parse() : array

Begin parsing the CSV file.

Examples

Get a list of .co.uk domains the PowerMTA server is connected to

$powermtaObj = new PowerMta();
$powermtaObj->setHost('powermta.domain');
$xml = $powermtaObj->domains(array('domain' => '*.co.uk', 'connected' => 'yes'));
$xmlObj = new SimpleXMLElement($xml);

Download and parse an accounting file for aol.com bounce records

$powermtaObj = new PowerMta();
$powermtaObj->setHost('powermta.domain');
$powermtaObj->getFile('/var/log/pmta/acct-2012-01-01-0000.csv');
$powermtaObj->getCsv()->addFilter('type', 'b');
$powermtaObj->getCsv()->addFilter('rcpt', '/aol.com$/');
$powermtaObj->getCsv()->setLineCallback('csvCallback');
$powermtaObj->getCsv()->parse();
$powermtaObj->deleteFile();
function csvCallback($lineArray) {
    print_r($lineArray);
}

Download

 
 

  • John

    Great Article,
    do you guys have any manual on how to implement this?

  • santu

    We are providing bulk email solution
    Cheap Dedicated server with multiple IP Address
    PowerMTA email Server and Interspire Email marketer
    Contact Us
    Skype ID : san2roy
    Gtalk ID : san2roy
    Email : san2roy @ gmail .com