RFC 2882 to RFC 2882 / HTTP API Methods
Overview
BrandMyMail HTTP API transformation method allows you to generate branded RFC2882 message by providing message object in RFC 2882 format.
URL
https://www.brandmymail.com/api/{version}/transform.{format}
Supported HTTP Methods
POST
Requires Authentication
true
Request Parameters
template - ID of the BrandMyMail template you want branded with.
email - Message in RFC 2882 format.
Response Parameters
success - Status of transformation. Possible Values: true or false.
created_at - Server time when request was processed.
email - Email message according to standard RFC2882.
Response Example (JSON)
{
“success”:true,
“results”:
{
“created_at”:”Tue, 17 Jan 2012 17:48:00 -0000”,
“email”:“branded email in RFC2882 message format”
}
}
Response Example (XML)
Tue, 17 Jan 2012 17:48:00 -0000
branded email in RFC2882 message format
Error Codes
403 Authentication Failed - BrandMyMail can't validate your API Access Key
429 API Limit Reached - User reached max number of BrandMyMail requests
405 Method Not Allowed - Unexpected HTTP Method for the request
412 Requested Template does not exist - BrandMyMail can't find template you specified in the request
415 Unsupported email format - BrandMyMail can’t parse email message in the request
400 Can't decode incoming JSON - BrandMyMail can’t parse JSON in the request
400 Bad Request - General user exception
Code Example
#!/usr/bin/python
import argparse
import email.parser
import json
import sys
import urllib2
import urllib
from smtplib import SMTP
arg_parser = argparse.ArgumentParser(description='Brand RFC2882 mail', \
epilog='Reads an RFC2882 mail message from the standard input.')
arg_parser.add_argument('apiuser', help='HTTP API Access Key username')
arg_parser.add_argument('apisecret', help='HTTP API Access Key secret')
arg_parser.add_argument('template', help='BrandMyMail Template ID')
args = arg_parser.parse_args()
# Create a message object from standard input
parser = email.parser.Parser()
msg = parser.parse(sys.stdin)
request = {}
request['auth'] = {'user': args.apiuser, 'secret': args.apisecret}
request['config'] = {'template': args.template}
request['data'] = {'email': msg.as_string()}
request_json = json.dumps(request)
host = "https://www.brandmymail.com/api/v1/transform.json"
req = urllib2.Request(host, request_json, {
'Content-Type':'application/json',
'Content-Length': len(request_json)
})
response_stream = urllib2.urlopen(req)
response = json.loads(response_stream.read())
if response['success']:
msg = response['results']['email']
smtp = SMTP()
smtp.connect(host=MY_EMAIL_HOST, port=MY_EMAIL_PORT)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(MY_EMAIL_HOST_USER, MY_EMAIL_HOST_PASSWORD)
smtp.sendmail('jo[email protected]', '[email protected]', msg)
smtp.quit()