This repo is a Nawah Package that allows developers to integrate Mailgun into Nawah apps using Gateway Controller. This packages offers two gateways; mailgun_messages
which allows developers to send messages with Mailgun REST API, and mailgun_newsletters
which allows developers to manage Mailgun newsletters subscriptions using Mailgun REST API.
- From your app directory run:
nawah packages add gateway_mailgun
- Add
mailgun
Var tonawah_app.py
App Config:
vars = {
'mailgun': {
'key': 'MAILGUN_API_KEY',
'newsletters': {
# If you are not using this gateway to manage newsletters keep newsletters present but empty
'NEWSLETTER_ID': 'NEWSLETTER_REST_URI',
},
'senders': {
# If you are not using this gateway to send messages keep senders present but empty
'SENDER_ID': {
'uri': 'SENDER_REST_URI',
'sender_name': 'NAME_OF_SENDER',
'sender_email': 'EMAIL_ADDRESS_OF_SENDER',
}
},
}
}
mailgun_messages
gateway requires following arguments:subject
: Subject of the message being sent. Typestr
.addr_to
: Email address the message is being sent to. Typestr
.content
ortemplate
: One of these two arguments should be present:content
: Literal message content to be sent. Typestr
.template
: Template name registered in Mailgun to be used for this message. Typestr
.
data
: When sending message withtemplate
you can pass set of values to replace Mailgun template variables with. Typedict
.sender
ormailgun_auth
: One of these two arguments should be present:sender
: Sender identifier from one ofmailgun.senders
. Typestr
.mailgun_auth
: Value used to pass dynamic API credentials with following values (Typedict
):key
: Mailgun API key to be used. Typestr
.uri
: Mailgun REST API URI for message sending request. Typestr
.sender_name
: Name of the sender to be present on message. Typestr
.sender_email
: Sender email address to be present on message. Typestr
.
- Use
mailgun_messages
using Nawah Gateway Controller:
from nawah.gateway import Gateway
Gateway.send(gateway='mailgun_messages', subject=subject, addr_to=addr_to, content=content, sender=sender)
Gateway.send(gateway='mailgun_messages', subject=subject, addr_to=addr_to, template=template, data=data, sender=sender)
Gateway.send(gateway='mailgun_messages', subject=subject, addr_to=addr_to, content=content, mailgun_auth=mailgun_auth)
mailgun_newsletters
gateway requires following arguments:subscribed
: Boolean value stating whether the email address is subscribed to newsletter or not. Typebool
.address
: Email address to be added to newsletter. Typestr
.name
: Name of the email address owner. Typestr
.description
: Description of the request begin sent, for internal uses. Typestr
.newsletter
ormailgun_auth
: One of these two arguments should be present:newsletter
: Newsletter identifier from one ofmailgun.newsletters
. Typestr
.mailgun_auth
: Value used to pass dynamic API credentials with following values (Typedict
):key
: Mailgun API key to be used. Typestr
.uri
: Mailgun REST API URI for newsletter request. Typestr
.
- Use
mailgun_newsletters
using Nawah Gateway Controller:
from nawah.gateway import Gateway
Gateway.send(gateway='mailgun_newsletters', subscribed=subscribed, address=address, name=name, description=description, newsletter=newsletter)
Gateway.send(gateway='mailgun_newsletters', subscribed=subscribed, address=address, name=name, description=description, mailgun_auth=mailgun_auth)