Python example

This example shows how you can send an email via the REST API of SMTPeter using Python.

The next code example shows a simple class called SMTPeter. The constructor of the class takes your access token as its input. Currently only the post() member function is implemented with which you can send an email instruction to SMTPeter.

import requests
import json
import pprint

class SMTPeter:

    # constructor
    def __init__(self, accesstoken):
        # Set token
        self.token = str(accesstoken)

    # post method
    def post(self, method, fields):
        # Create correct url
        url = "" + method + "?access_token=" + self.token

        # Create JSON
        data_json = json.dumps(fields)

        # Set content type to JSON
        headers = {'Content-type': 'application/json'}

        # Make request and return response
        return, data=data_json, headers=headers)

Using this class is easy. Once you have prepared your data in JSON format it might look something like this:

"envelope"  : "",
"recipient" : "",
"subject"   : "This is the mail subject",
"from"      : "",
"to"        : "",
"html"      : "<html><head><style>body { font-weight: 600; }</style></head><body>This is the html version.</body></html>",
"text"      : "And this is the text version"

We can then send this data with the following script:

# your token
token = "abcde"

# initialize SMTPeter with token
mySMTPeterConnection = SMTPeter(token)

# import your data in a variable data here with a method of your choosing

# use the SMTPeter connection to call the POST method, using the 
# data you just retrieved
response ="send", data)

# print the server response in JSON format

If the email was sent successfully you should have received an array as the API response, which contains message IDs and their corresponding email addresses.

More infomation