MailerSend Python SDK
$ python3 -m pip install mailersend
import mailersend
mailer = mailersend.NewApiClient()
subject = "Subject"
text = "This is the text content"
html = "<p>This is the HTML content</p>"
my_mail = "owner@verified_domain.com"
recipient_list = [ 'pamela@dundermifflin.com',
'dwight@dunderfmifflin.com', 'jim@dundermifflin.com']
mailer.send(my_mail, recipient_list, subject, html, text, None, None)
import mailersend
mailer = mailersend.NewApiClient()
subject = "Subject"
template_id = '351ndrxrx45zqx8k'
my_mail = "owner@verified_domain.com"
recipient_list = [ 'pamela@dundermifflin.com',
'dwight@dunderfmifflin.com', 'jim@dundermifflin.com']
mailer.send(my_mail, recipient_list, subject, None, None, template_id, None)
import mailersend
mailer = mailersend.NewApiClient()
subject = "Hello from {$company}"
text = "This is the text content"
html = "<p>This is the HTML content, {$name}</p>"
my_mail = "owner@verified_domain.com"
recipient_list = [ 'pamela@dundermifflin.com',
'dwight@dunderfmifflin.com', 'jim@dundermifflin.com']
variables = [{
"email": "pamela@dundermifflin.com",
"substitutions": [{
"var": "name",
"value": "Pam",
},
{
"var": "company",
"value": "Dunder Mifflin",
},]
}]
mailer.send(my_mail, recipient_list, subject, html, text, None, variables)
This helper function allows to programatically gather IDs for domains and subscribers for later
use in the code. Takes 2 arguments, category
and name
, and returns the respective ID of the searched-for item.
Available options for category:
- domains
- recipients
import mailersend
mailer = mailersend.NewApiClient()
mailer.getIdByName("domains", "mailersend.com")
import mailersend
mailer = mailersend.NewApiClient()
mailer.getRecipientsForDomain('<domainId>')
The activity list can be filtered using the available query parameters, found at MailerSend official documentation.
import mailersend
mailer = mailersend.NewApiClient()
mailer.getDomainActivity("DOMAIN_ID")
The activity list can be filtered using the available query parameters, found at MailerSend official documentation.
import mailersend
mailer = mailersend.NewApiClient()
eventList = [
'processed', 'queued', 'sent', 'delivered',
'soft_bounced', 'hard_bounced', 'junk', 'opened',
'clicked', 'unsubscribed', 'spam_complaints',
]
mailer.getActivityByDate('<domainId>', 1443661141, 1620772339, '<groupBy>', eventList)
The activity list can be filtered using the available query parameters, found at MailerSend official documentation.
import mailersend
mailer = mailersend.NewApiClient()
mailer.getDomains("DOMAIN_ID")
There is a function that can be used per domain setting (available domain settings).
A full example for all domain settings is showcased here:
import mailersend
mailer = mailersend.NewApiClient()
# enable send_paused
mailer.sendPaused('<domainID>', True)
# enable clicks tracking
mailer.trackClicks('<domainID>', True)
# enable opens tracking
mailer.trackOpens('<domainID>', True)
# enable unsubscribes tracking
mailer.trackUnsubscribe('<domainID>', True)
# add unsubscribe custom plaintext string
mailer.trackUnsubscribePlain('<domainID>', 'Click here to unsubscribe')
# add unsubscribe custom HTML string
mailer.trackUnsubscribeHtml('<domainID>', '<p>Click here to <a href=\"{$unsubscribe}\">unsubscribe<\/a><\/p>')
# enable content tracking
mailer.trackContent('<domainID>', True)
# enable custom tracking
mailer.customTracking('<domainID>', True)
# set custom tracking subdomain
mailer.setCustomTrackingSubdomain('<domainID>', 'track.dundermifflin.com')
import mailersend
mailer = mailersend.NewApiClient()
mailer.deleteDomain(mailer.getIdByName('<domainID>')
To be implemented
In case you find any bugs, submit an issue directly here in GitHub.
You are welcome to create SDK for any other programming language.
If you have any troubles using our API or SDK free to contact our support by email info@mailersend.com
The official documentation is at https://developers.mailersend.com