Skip to content

Instantly share code, notes, and snippets.

@chauek
Created January 3, 2012 10:07
Show Gist options
  • Save chauek/1554329 to your computer and use it in GitHub Desktop.
Save chauek/1554329 to your computer and use it in GitHub Desktop.
Example of MailZ API
<?php
/**
*
* Implementation of sample scenario using MailZ API:
*
* Send message
* Show message status
*
* @author Pawel Chalkowski
* http://implix.com
* http://www.mailz.com
*
*/
# JSON-RPC module is required
# available at http://github.com/GetResponse/DevZone/blob/master/API/lib/jsonRPCClient.php
# alternate version available at http://jsonrpcphp.org/
require_once 'jsonRPCClient.php';
# your API key
# available at https://app.mailz.com/api_key.html
$api_key = 'ENTER_YOUR_API_KEY_HERE';
# API URL
$api_url = 'http://api.mailz.com';
# initialize JSON-RPC client
$client = new jsonRPCClient($api_url);
$result = NULL;
# send message
try {
$result = $client->send(
$api_key,
array (
'from' => array ( 'name' => 'Me', 'email' => '[email protected]'),
'to' => array ( 'name' => 'You', 'email' => '[email protected]'),
'content' => array (
'subject' => 'Hello world',
'plain' => 'Test',
'html' => '<h1>Test</h1>'
),
'track' => array (
'opens' => true,
'clicks' => false
),
'suppression' => true
)
);
}
catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
echo "Message send with ID:\n";
echo $result['SEND_ID'] . "\n";
$result = NULL;
# get status
try {
$result = $client->status(
$api_key,
array (
'SEND_ID' => $result['SEND_ID']
)
);
}
catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
echo 'Status:';
print_r($result);
?>
#!/usr/bin/python
"""
Implementation of sample scenario using MailZ API:
Send message
Show account statistics
Author:
Pawel Chalkowski
http://implix.com
http://www.mailz.com
"""
import pprint
import sys
# JSON-RPC module is required
# available at http://json-rpc.org/wiki/python-json-rpc
from jsonrpc import ServiceProxy
# your API key
# available at https://app.mailz.com/api_key.html
api_key = 'ENTER_YOUR_API_KEY_HERE'
# API URL
api_url = 'http://api.mailz.com'
# initialize JSON-RPC client
client = ServiceProxy(api_url)
result = None
# send message
try:
result = client.send(
api_key,
{
"from" : {"name" : "Me","email" : "[email protected]"},
"to" : {"name" : "You","email" : "[email protected]"},
"content" : {
"subject" : "Hello world",
"plain" : "Test",
"html" : "<h1>Test</h1>"
},
"track" :
{
"opens" : True,
"clicks" : False
},
"suppression" : True
}
)
except Exception, e:
# check for communication and response errors
# implement handling if needed
#
# detailed JSONRPCException and JSONDecodeException
# are also available in jsonrpc package
sys.exit(e)
# uncomment this line to preview data structure
#pprint.pprint(result)
SEND_ID = result['SEND_ID'];
# get status of send message
try:
result = client.status(
api_key,
{
"SEND_ID" : SEND_ID
}
)
except Exception, e:
# check for communication and response errors
# implement handling if needed
#
# detailed JSONRPCException and JSONDecodeException
# are also available in jsonrpc package
sys.exit(e)
# uncomment this line to preview data structure
# pprint.pprint(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment