Skip to main content

mailjet is a django app to implement the mailjet REST API

Project description

Introduction

Mailjet is a real-time Cloud Emailing platform and this is a python library to access the Mailjet Web API.

Installation

  • Clone this repository:

git clone https://github.com/WoLpH/mailjet

  • cd into the cloned directory and execute:

python setup.py install.

The settings can be configured from a Django settings file through MAILJET_API_KEY and MAILJET_SECRET_KEY, or through environment variables with the same name.

i.e.

export MAILJET_API_KEY='YOUR_API_KEY'
export MAILJET_SECRET_KEY='YOUR_SECRET_KEY'

Alternatively, you can just pass the API key and Secret key as parameters when initializing the mailjet API as follows:

import mailjet

mailjet_api = mailjet.Api(api_key='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY')

Usage

  • To get your account and profile information:

import mailjet

mailjet_api = mailjet.Api(api_key='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY')
account_info = mailjet_api.user.infos()

acount_info would now be assigned the following python dict:

{
    'status': 'OK',
    'infos': {
        'username': 'user@domain.com',
        'firstname': 'firstname',
        'locale': 'en_US',
        'lastname': 'lastname',
        'company_name': 'company_name',
        'contact_phone': None,
    }
}
  • Create a new list of contacts, following on from the previous example:

contact_list = mailjet_api.lists.create(
    label='test',
    name='Test list',
    method='POST'
)

contact_list will now contain a dictionary with the status and list id as below:

{
    'status': 'OK',
    'contact_id': 000000000
}
  • You can now add contacts to your list using the contact_id:

mailjet_api.lists.addcontact(
    contact='example@example.com',
    id=contact_list['list_id'],
    method='POST'
)

FAQ

How do I give reserved python keywords as parameters?

Methods such as creating a campaign require you to use reserved python keywords, such as from - hence, in order to overcome this, do the following:

params = dict()
params['method'] ='POST'
params['subject'] = 'My first campaign'
params['list_id'] = contact_list['list_id']
params['lang'] = 'en'
params['from'] = 'noreply@example.com'
params['from_name'] = 'Your name'
params['footer'] = 'default'
campaign = api.message.createcampaign(**params)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailjet-1.3.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file mailjet-1.3.1.tar.gz.

File metadata

  • Download URL: mailjet-1.3.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mailjet-1.3.1.tar.gz
Algorithm Hash digest
SHA256 7af682ecd7efa71815f564d78352d57f9625d702189a1d85d6832a1309e4f5ae
MD5 3f8505ef0d7cd6240aafa8ecd7ab3217
BLAKE2b-256 c149a5b1bbc3f0bd0862ab49c39f6b408106dd621e2a5df5b5ab47832698a79d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page