Package: mailersend
MailerSend Python SDKTable of ContentsTable of ContentsInstallationRequirementsAuthenticationUsageEmailSend an emailAdd CC, BCC recipientsSend a template-based emailAdvanced personalizationSimple personalizationSend email with attachmentEmail VerificationGet all email verification listsGet a single email verification listCreate a email verification listVerify a listGet list resultsBulk EmailSend bulk emailGet bulk email statusActivityGet a list of activities (simple)Get a list of activities (full)AnalyticsActivity data by dateOpens by countryOpens by user-agent nameOpens by reading environmentInbound RoutesGet a list of inbound routesGet a single inbound routeAdd an inbound routeUpdate an inbound routeDelete an inbound routeDomainsGet a list of domainsGet a single domainGet a single domain using helper functionAdd a domainDelete a domainGet a list of recipients per domainUpdate domain settingsGet DNS RecordsVerify a domainMessagesGet a list of messagesGet a single messageScheduled messagesGet a list of scheduled messagesGet a single scheduled messageDelete a scheduled messageRecipientsGet a list of recipientsGet a single recipientDelete a recipientGet recipients from a blocklistGet recipients from hard bouncesGet recipients from spam complaintsGet recipients from unsubscribesAdd recipients to blocklistAdd hard bounced recipientsAdd spam complaintsAdd recipients to unsubscribe listDelete recipients from blocklistDelete hard bounced recipientsDelete spam complaintsDelete recipients from unsubscribe listTokensCreate a tokenPause / Unpause TokenDelete a TokenTemplatesGet a list of templatesGet a single templateDelete templateWebhooksGet a list of webhooksGet a single webhookCreate a WebhookCreate a disabled webhookUpdate a WebhookDisable/Enable a WebhookDelete a WebhookSMSSending SMS messagesSMS ActivityGet a list of activitiesGet activity of a single messageSMS Phone NumbersGet a list of SMS phone numbersGet an SMS phone numberUpdate a single SMS phone numberDelete an SMS phone numberSMS RecipientsGet a list of SMS recipientsGet an SMS recipientUpdate a single SMS recipientSMS MessagesGet a list of SMS messagesGet an SMS messageSMS WebhooksGet a list of SMS webhooksGet a single SMS webhookCreate an SMS webhookUpdate a single SMS webhookDelete an SMS webhookGet a list of SMS webhooksSMS InboudsGet a list of SMS inbound routesGet a single SMS inbound routeCreate an SMS inbound routeUpdate an SMS inbound routeDelete an SMS inbound routeSender IdentitiesGet a list of sender identitiesGet a sender identityCreate a sender identityUpdate a sender identityDelete a sender identityAPI QuotaGet API QuotaTroubleshootingEmails not being sentTestingAvailable endpointsSupport and FeedbackLicenseInstallation$ python -m pip install mailersendRequirementsPython > 3.6.1PythonpipAn API Key frommailersend.comAuthenticationWe recommend you to defineMAILERSEND_API_KEYenvironment variable in the.envfile, and use it to store the API key.Using environment variablefrommailersendimportemails# assigning NewEmail() without params defaults to MAILERSEND_API_KEY env varmailer=emails.NewEmail()# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]reply_to={"name":"Name","email":"reply@domain.com",}mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello!",mail_body)mailer.set_html_content("This is the HTML content",mail_body)mailer.set_plaintext_content("This is the text content",mail_body)mailer.set_reply_to(reply_to,mail_body)# using print() will also return status code and datamailer.send(mail_body)Explicit declarationfrommailersendimportemailsmailer=emails.NewEmail("my-api-key")# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]reply_to={"name":"Name","email":"reply@domain.com",}mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello!",mail_body)mailer.set_html_content("This is the HTML content",mail_body)mailer.set_plaintext_content("This is the text content",mail_body)mailer.set_reply_to(reply_to,mail_body)# using print() will also return status code and datamailer.send(mail_body)UsageEmailSend an emailfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]reply_to={"name":"Name","email":"reply@domain.com",}mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello!",mail_body)mailer.set_html_content("This is the HTML content",mail_body)mailer.set_plaintext_content("This is the text content",mail_body)mailer.set_reply_to(reply_to,mail_body)# using print() will also return status code and datamailer.send(mail_body)Add CC, BCC recipientsfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]cc=[{"name":"CC","email":"cc@client.com"}]bcc=[{"name":"BCC","email":"bcc@client.com"}]mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello!",mail_body)mailer.set_html_content("This is the HTML content",mail_body)mailer.set_plaintext_content("This is the text content",mail_body)mailer.set_cc_recipients(cc,mail_body)mailer.set_bcc_recipients(bcc,mail_body)mailer.send(mail_body)Send a template-based emailfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]variables=[{"email":"your@client.com","substitutions":[{"var":"foo","value":"bar"},]}]mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello from {$company}",mail_body)mailer.set_template("templateID",mail_body)mailer.set_simple_personalization(variables,mail_body)mailer.send(mail_body)Advanced personalizationfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]personalization=[{"email":"test@mailersend.com","data":{"var":"value","boolean":True,"object":{"key":"object-value"},"number":2,"array":[1,2,3]}}]mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello from {$company}",mail_body)mailer.set_html_content("This is the HTML content, {$name}",mail_body)mailer.set_plaintext_content("This is the text content, {$name}",mail_body)mailer.set_advanced_personalization(personalization,mail_body)mailer.send(mail_body)Simple personalizationfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]variables=[{"email":"your@client.com","substitutions":[{"var":"foo","value":"bar"},]}]mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello from {$foo}",mail_body)mailer.set_html_content("This is the HTML content, {$foo}",mail_body)mailer.set_plaintext_content("This is the text content, {$foo}",mail_body)mailer.set_simple_personalization(variables,mail_body)mailer.send(mail_body)Send email with attachmentfrommailersendimportemailsimportbase64fromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))# define an empty dict to populate with mail valuesmail_body={}mail_from={"name":"Your Name","email":"your@domain.com",}recipients=[{"name":"Your Client","email":"your@client.com",}]variables=[{"email":"your@client.com","substitutions":[{"var":"foo","value":"bar"},]}]attachment=open('path-to-file','rb')att_read=attachment.read()att_base64=base64.b64encode(bytes(att_read))attachments=[{"id":"my-attached-file","filename":"file.jpg","content":f"{att_base64.decode('ascii')}","disposition":"attachment"}]mailer.set_mail_from(mail_from,mail_body)mailer.set_mail_to(recipients,mail_body)mailer.set_subject("Hello from {$foo}",mail_body)mailer.set_html_content("This is the HTML content, {$foo}",mail_body)mailer.set_plaintext_content("This is the text content, {$foo}",mail_body)mailer.set_simple_personalization(variables,mail_body)mailer.set_attachments(attachments,mail_body)mailer.send(mail_body)Email VerificationGet all email verification listsfrommailersendimportemail_verificationfromdotenvimportload_dotenvload_dotenv()mailer=email_verification.NewEmailVerification(os.getenv('MAILERSEND_API_KEY'))mailer.get_all_lists()Get a single email verification listfrommailersendimportemail_verificationfromdotenvimportload_dotenvload_dotenv()mailer=email_verification.NewEmailVerification(os.getenv('MAILERSEND_API_KEY'))email_verification_list_id=123456mailer.get_list(email_verification_list_id)Create a email verification listfrommailersendimportemail_verificationfromdotenvimportload_dotenvload_dotenv()mailer=email_verification.NewEmailVerification(os.getenv('MAILERSEND_API_KEY'))name="My List"emails=["some@email.com","another@email.com"]mailer.create_list(name,emails)Verify a listfrommailersendimportemail_verificationfromdotenvimportload_dotenvload_dotenv()mailer=email_verification.NewEmailVerification(os.getenv('MAILERSEND_API_KEY'))email_verification_list_id=123456mailer.verify_list(email_verification_list_id)Get list resultsfrommailersendimportemail_verificationfromdotenvimportload_dotenvload_dotenv()mailer=email_verification.NewEmailVerification(os.getenv('MAILERSEND_API_KEY'))email_verification_list_id=123456mailer.get_list_results(email_verification_list_id)Bulk EmailSend bulk emailfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))mail_list=[{"from":{"email":"your@domain.com","name":"Your Name"},"to":[{"email":"your@client.com","name":"Your Client"}],"subject":"Subject","text":"This is the text content","html":"<p>This is the HTML content</p>",},{"from":{"email":"your@domain.com","name":"Your Name"},"to":[{"email":"your@client.com","name":"Your Client"}],"subject":"Subject","text":"This is the text content","html":"<p>This is the HTML content</p>",}]print(mailer.send_bulk(mail_list))Get bulk email statusfrommailersendimportemailsfromdotenvimportload_dotenvload_dotenv()mailer=emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_bulk_status_by_id("bulk-email-id"))ActivityGet a list of activities (simple)frommailersendimportactivityfromdotenvimportload_dotenvload_dotenv()mailer=activity.NewActivity(os.getenv('MAILERSEND_API_KEY'))mailer.get_domain_activity("domain-id")Get a list of activities (full)frommailersendimportactivityfromdotenvimportload_dotenvload_dotenv()mailer=activity.NewActivity(os.getenv('MAILERSEND_API_KEY'))page=1limit=20date_from=1623073576date_to=1623074976events=["queued","sent","delivered","soft-bounced","hard-bounced","junk","opened","clicked","unsubscribed","spam_complaints",]mailer.get_domain_activity("domain-id",page,limit,date_from,date_to,events)AnalyticsActivity data by datefrommailersendimportanalyticsfromdotenvimportload_dotenvload_dotenv()mailer=analytics.NewAnalytics(os.getenv('MAILERSEND_API_KEY'))date_from=1623073576date_to=1623074976events=["sent",]# optional argumentsdomain_id="domain-id"group_by="days"mailer.get_activity_by_date(date_from,date_to,events,domain_id,group_by)Opens by countryfrommailersendimportanalyticsfromdotenvimportload_dotenvload_dotenv()mailer=analytics.NewAnalytics(os.getenv('MAILERSEND_API_KEY'))date_from=1623073576date_to=1623074976# optional argumentsdomain_id="domain-id"mailer.get_opens_by_country(date_from,date_to,domain_id)Opens by user-agent namefrommailersendimportanalyticsfromdotenvimportload_dotenvload_dotenv()mailer=analytics.NewAnalytics(os.getenv('MAILERSEND_API_KEY'))date_from=1623073576date_to=1623074976# optional argumentsdomain_id="domain-id"mailer.get_opens_by_user_agent(date_from,date_to,domain_id)Opens by reading environmentfrommailersendimportanalyticsfromdotenvimportload_dotenvload_dotenv()mailer=analytics.NewAnalytics(os.getenv('MAILERSEND_API_KEY'))date_from=1623073576date_to=1623074976# optional argumentsdomain_id="domain-id"mailer.get_opens_by_reading_environment(date_from,date_to,domain_id)Inbound RoutesGet a list of inbound routesfrommailersendimportinbound_routingfromdotenvimportload_dotenvload_dotenv()mailer=inbound_routing.NewInbound(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_inbound_routes())Get a single inbound routefrommailersendimportinbound_routingfromdotenvimportload_dotenvload_dotenv()mailer=inbound_routing.NewInbound(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_inbound_by_id("inbound-id"))Add an inbound routefrommailersendimportinbound_routingfromdotenvimportload_dotenvload_dotenv()mailer=inbound_routing.NewInbound(os.getenv('MAILERSEND_API_KEY'))options={}_catch_filter={"type":"catch_recipient","filters":[{"comparer":"equal","value":"test"}]}_match_filter={"type":"match_all"}_forwards=[{"type":"webhook","value":"https://www.mailersend.com/hook"}]mailer.set_name("Example route",options)mailer.set_domain_enabled(True,options)mailer.set_inbound_domain("test.mailersend.com",options)mailer.set_catch_filter(_catch_filter,options)print(mailer.add_inbound_route())Update an inbound routefrommailersendimportinbound_routingfromdotenvimportload_dotenvload_dotenv()route_id="inbound-route-id"mailer=inbound_routing.NewInbound(os.getenv('MAILERSEND_API_KEY'))options={}_catch_filter={"type":"catch_recipient","filters":[{"comparer":"equal","value":"test"}]}_match_filter={"type":"match_all"}_forwards=[{"type":"webhook","value":"https://www.mailersend.com/hook"}]mailer.set_name("Example route",options)mailer.set_domain_enabled(True,options)mailer.set_inbound_domain("test.mailersend.com",options)mailer.set_catch_filter(_catch_filter,options)print(mailer.update_inbound_route(route_id))Delete an inbound routefrommailersendimportinbound_routingfromdotenvimportload_dotenvload_dotenv()route_id="inbound-route-id"mailer=inbound_routing.NewInbound(os.getenv('MAILERSEND_API_KEY'))print(mailer.delete_inbound_route(route_id))DomainsGet a list of domainsfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.get_domains()Get a single domainfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.get_domain_by_id("domain-id")Get a single domain using helper functionfrommailersendimportdomainsfrommailersendimportutilsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))helper=utils.NewHelper(os.getenv('MAILERSEND_API_KEY'))mailer.get_domain_by_id(helper.get_id_by_name("domains","domain-name"))Add a domainYou can find a full list of settingshere.frommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))domain_data={"name":"mydomain.com","return_path_subdomain":"rpsubdomain","custom_tracking_subdomain":"ctsubdomain","inbound_routing_subdomain":"irsubdomain"}mailer.add_domain("name",domain_data)Delete a domainfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.delete_domain("domain-id")Get a list of recipients per domainfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.get_recipients_for_domain("domain-id")Update domain settingsYou can find a full list of settingshere.frommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))domain_data={"send_paused":True,"track_clicks":True,"track_opens":True,"track_unsubscribe":True,"track_unsubscribe_html":"<p>Click to <a href='{$unsubscribe}'>unsubscribe</a></p>","track_unsubscribe_plain":"Click to unsubscribe: {$unsubscribe}","track_content":True,"custom_tracking_enabled":True,"custom_tracking_subdomain":"email","precedence_bulk":False}mailer.update_domain_setting("domain-id",domain_data)Get DNS Recordsfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.get_dns_records("domain-id")Verify a domainfrommailersendimportdomainsfromdotenvimportload_dotenvload_dotenv()mailer=domains.NewDomain(os.getenv('MAILERSEND_API_KEY'))mailer.verify_domain("domain-id")MessagesGet a list of messagesfrommailersendimportmessagesfromdotenvimportload_dotenvload_dotenv()mailer=messages.NewMessage(os.getenv('MAILERSEND_API_KEY'))mailer.get_messages()Get a single messagefrommailersendimportmessagesfromdotenvimportload_dotenvload_dotenv()mailer=messages.NewMessage(os.getenv('MAILERSEND_API_KEY'))mailer.get_message_by_id("message-id")Scheduled messagesGet a list of scheduled messagesfrommailersendimportscheduled_messagesfromdotenvimportload_dotenvload_dotenv()mailer=scheduled_messages.NewMessageSchedule(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_scheduled_messages())Get a single scheduled messagefrommailersendimportscheduled_messagesfromdotenvimportload_dotenvload_dotenv()mailer=scheduled_messages.NewMessageSchedule(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_scheduled_message_by_id("scheduled-message-id"))Delete a scheduled messagefrommailersendimportscheduled_messagesfromdotenvimportload_dotenvload_dotenv()mailer=scheduled_messages.NewMessageSchedule(os.getenv('MAILERSEND_API_KEY'))print(mailer.delete_scheduled_message("scheduled-message-id"))RecipientsGet a list of recipientsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_recipients()Get a single recipientfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_recipient_by_id("recipient-id")Delete a recipientfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.delete_recipient("recipient-id")Get recipients from a blocklistfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_recipients_from_blocklist("domain-id")Get recipients from hard bouncesfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_hard_bounces("domain-id")Get recipients from spam complaintsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_spam_complaints("domain-id")Get recipients from unsubscribesfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))mailer.get_unsubscribes("domain-id")Add recipients to blocklistUsing recipients:frommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=['blocked@client.com']mailer.add_to_blocklist("domain-id",recipients=recipient_list)Using patterns:frommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_patterns=['*@client.com']mailer.add_to_blocklist("domain-id",patterns=recipient_patterns)Add hard bounced recipientsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.add_hard_bounces("domain-id",recipient_list)Add spam complaintsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.add_spam_complaints("domain-id",recipient_list)Add recipients to unsubscribe listfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.add_unsubscribes("domain-id",recipient_list)Delete recipients from blocklistfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.delete_from_blocklist("domain-id",recipient_list)Delete hard bounced recipientsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.delete_hard_bounces("domain-id",recipient_list)Delete spam complaintsfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.delete_spam_complaints("domain-id",recipient_list)Delete recipients from unsubscribe listfrommailersendimportrecipientsfromdotenvimportload_dotenvload_dotenv()mailer=recipients.NewRecipient(os.getenv('MAILERSEND_API_KEY'))recipient_list=["your@client.com"]mailer.delete_unsubscribes("domain-id",recipient_list)TokensCreate a tokenfrommailersendimporttokensfromdotenvimportload_dotenvload_dotenv()mailer=tokens.NewToken(os.getenv('MAILERSEND_API_KEY'))scopes=["email_full","analytics_read"]mailer.create_token("my-token",scopes)Because of security reasons, we only allow access token appearance once during creation. In order to see the access token created you can do:frommailersendimporttokensfromdotenvimportload_dotenvload_dotenv()mailer=tokens.NewToken(os.getenv('MAILERSEND_API_KEY'))scopes=["email_full","analytics_read"]print(mailer.create_token("my-token",scopes))Pause / Unpause Tokenfrommailersendimporttokensfromdotenvimportload_dotenvload_dotenv()mailer=tokens.NewToken(os.getenv('MAILERSEND_API_KEY'))# pausemailer.update_token("my-token")# unpausemailer.update_token("my-token",pause=False)Delete a Tokenfrommailersendimporttokensfromdotenvimportload_dotenvload_dotenv()mailer=tokens.NewToken(os.getenv('MAILERSEND_API_KEY'))mailer.delete_token("token-id")TemplatesGet a list of templatesfrommailersendimporttemplatesfromdotenvimportload_dotenvload_dotenv()mailer=templates.NewTemplate(os.getenv('MAILERSEND_API_KEY'))mailer.get_templates()Get a single templatefrommailersendimporttemplatesfromdotenvimportload_dotenvload_dotenv()mailer=templates.NewTemplate(os.getenv('MAILERSEND_API_KEY'))template_id=1234mailer.get_template_by_id()Delete templatefrommailersendimporttemplatesfromdotenvimportload_dotenvload_dotenv()mailer=templates.NewTemplate(os.getenv('MAILERSEND_API_KEY'))template_id=1234mailer.delete_template()WebhooksGet a list of webhooksfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()mailer=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))mailer.get_webhooks("domain-id")Get a single webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()mailer=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))mailer.get_webhook_by_id("webhook-id")Create a Webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()webhookEvents=['activity.sent','activity.delivered']webhook=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))webhook.set_webhook_url("https://webhooks.mysite.com")webhook.set_webhook_name("my first webhook")webhook.set_webhook_events(webhookEvents)webhook.set_webhook_domain("domain-id")webhook.create_webhook()Create a disabled webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()webhookEvents=['activity.sent','activity.delivered']webhook=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))webhook.set_webhook_url("https://webhooks.mysite.com")webhook.set_webhook_name("my first webhook")webhook.set_webhook_events(webhookEvents)webhook.set_webhook_domain("domain-id")webhook.set_webhook_enabled(False)webhook.create_webhook()Update a Webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()webhook=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))webhook.update_webhook("webhook-id","name","a new webhook name")Disable/Enable a Webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()webhook=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))webhook.update_webhook("webhook-id","enabled",False)Delete a Webhookfrommailersendimportwebhooksfromdotenvimportload_dotenvload_dotenv()webhook=webhooks.NewWebhook(os.getenv('MAILERSEND_API_KEY'))webhook.delete_webhook("webhook-id")SMSSending SMS messagesWithout personalization:frommailersendimportsms_sendingfromdotenvimportload_dotenvload_dotenv()mailer=sms_sending.NewSmsSending(os.getenv('MAILERSEND_API_KEY'))# Number belonging to your account in E164 formatnumber_from="+11234567890"# You can add up to 50 recipient numbersnumbers_to=["+11234567891","+11234567892"]text="This is the text content"print(mailer.send_sms(number_from,numbers_to,text))With personalization:frommailersendimportsms_sendingfromdotenvimportload_dotenvload_dotenv()mailer=sms_sending.NewSmsSending(os.getenv('MAILERSEND_API_KEY'))# Number belonging to your account in E164 formatnumber_from="+11234567890"# You can add up to 50 recipient numbersnumbers_to=["+11234567891","+11234567892"]text="Hi {{name}} how are you?"personalization=[{"phone_number":"+11234567891","data":{"name":"Mike"}},{"phone_number":"+11234567892","data":{"name":"John"}}]print(mailer.send_sms(number_from,numbers_to,text,personalization))SMS ActivityGet a list of activitiesfrommailersendimportsms_activityfromdotenvimportload_dotenvload_dotenv()mailer=sms_activity.NewSmsActivity(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id=1365743date_from=1655157601date_to=1655158601status=["queued","failed"]page=1limit=200print(mailer.get_activities(sms_number_id=sms_number_id,date_from=date_from,date_to=date_to,status=status,page=page,limit=limit))Get activity of a single messagefrommailersendimportsms_activityfromdotenvimportload_dotenvload_dotenv()mailer=sms_activity.NewSmsActivity(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_message_id="62a9d12b07852eaf2207b417"print(mailer.get_activity(sms_message_id))SMS Phone NumbersGet a list of SMS phone numbersfrommailersendimportsms_phone_numbersfromdotenvimportload_dotenvload_dotenv()mailer=sms_phone_numbers.NewSmsNumbers(os.getenv('MAILERSEND_API_KEY'))#Request parameterspaused=Falseprint(mailer.get_phone_numbers(paused))Get an SMS phone numberfrommailersendimportsms_phone_numbersfromdotenvimportload_dotenvload_dotenv()mailer=sms_phone_numbers.NewSmsNumbers(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"print(mailer.get_phone_number(sms_number_id))Update a single SMS phone numberfrommailersendimportsms_phone_numbersfromdotenvimportload_dotenvload_dotenv()mailer=sms_phone_numbers.NewSmsNumbers(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"paused=Trueprint(mailer.update_phone_number(sms_number_id,paused))Delete an SMS phone numberfrommailersendimportsms_phone_numbersfromdotenvimportload_dotenvload_dotenv()mailer=sms_phone_numbers.NewSmsNumbers(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"print(mailer.delete_phone_number(sms_number_id))SMS RecipientsGet a list of SMS recipientsfrommailersendimportsms_recipientsfromdotenvimportload_dotenvload_dotenv()mailer=sms_recipients.NewSmsRecipients(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"status="active"print(mailer.get_recipients(status=status,sms_number_id=sms_number_id))Get an SMS recipientfrommailersendimportsms_recipientsfromdotenvimportload_dotenvload_dotenv()mailer=sms_recipients.NewSmsRecipients(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_recipient_id="627e756fd30078fb2208cc87"print(mailer.get_recipient(sms_recipient_id))Update a single SMS recipientfrommailersendimportsms_recipientsfromdotenvimportload_dotenvload_dotenv()mailer=sms_recipients.NewSmsRecipients(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_recipient_id="627e756fd30078fb2208cc87"status="opt_out"print(mailer.update_recipient(sms_recipient_id,status))SMS MessagesGet a list of SMS messagesfrommailersendimportsms_messagesfromdotenvimportload_dotenvload_dotenv()mailer=sms_messages.NewSmsMessages(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_messages())Get an SMS messagefrommailersendimportsms_messagesfromdotenvimportload_dotenvload_dotenv()#Request parameterssms_message_id="627e756fd30078fb2208cc87"mailer=sms_messages.NewSmsMessages(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_message(sms_message_id))SMS WebhooksGet a list of SMS webhooksfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"print(mailer.get_webhooks(sms_number_id))Get a single SMS webhookfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_webhook_id="aaui13enl12f2vzx"print(mailer.get_webhook(sms_webhook_id))Create an SMS webhookfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parametersurl="https://webhook-url.com"name="My Webhook Name"events=["sms.sent"]sms_number_id="9pq3enl6842vwrzx"enabled=Trueprint(mailer.create_webhook(url,name,events,sms_number_id,enabled))Update a single SMS webhookfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parametersurl="https://different-url.com"name="New Webhook Name"events=["sms.sent","sms.failed"],sms_webhook_id="aaui13enl12f2vzx"enabled=Falseprint(mailer.update_webhook(sms_webhook_id,url,name,events,enabled))Delete an SMS webhookfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_webhook_id="aaui13enl12f2vzx"print(mailer.delete_webhook(sms_webhook_id))Get a list of SMS webhooksfrommailersendimportsms_webhooksfromdotenvimportload_dotenvload_dotenv()mailer=sms_webhooks.NewSmsWebhooks(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="9pq3enl6842vwrzx"print(mailer.get_webhooks(sms_number_id))SMS InboudsGet a list of SMS inbound routesfrommailersendimportsms_inboundsfromdotenvimportload_dotenvload_dotenv()mailer=sms_inbounds.NewSmsInbounds(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="123456789"enabled=Truepage=1limit=25print(mailer.get_inbound_routes(sms_number_id,enabled,page,limit))Get a single SMS inbound routefrommailersendimportsms_inboundsfromdotenvimportload_dotenvload_dotenv()mailer=sms_inbounds.NewSmsInbounds(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_inbound_id="123456789"print(mailer.get_inbound_route(sms_inbound_id))Create an SMS inbound routefrommailersendimportsms_inboundsfromdotenvimportload_dotenvload_dotenv()mailer=sms_inbounds.NewSmsInbounds(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="123456789"name="My route"forward_url="https://some.url"filter={"comparer":"equal","value":"START"}enabled=Trueprint(mailer.create_inbound_route(sms_number_id,name,forward_url,filter,enabled))Update an SMS inbound routefrommailersendimportsms_inboundsfromdotenvimportload_dotenvload_dotenv()mailer=sms_inbounds.NewSmsInbounds(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_number_id="123456789"name="New name"forward_url="https://news.url"filter={"comparer":"contains","value":"some-value"}enabled=Trueprint(mailer.update_inbound_route(sms_number_id,name,forward_url,filter,enabled))Delete an SMS inbound routefrommailersendimportsms_inboundsfromdotenvimportload_dotenvload_dotenv()mailer=sms_inbounds.NewSmsInbounds(os.getenv('MAILERSEND_API_KEY'))#Request parameterssms_inbound_id="123456789"print(mailer.delete_inbound_route()(sms_inbound_id))Sender IdentitiesGet a list of sender identitiesfrommailersendimportsender_identitiesfromdotenvimportload_dotenvload_dotenv()mailer=sender_identities.NewSenderIdentity(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_identities())Get a sender identityfrommailersendimportsender_identitiesfromdotenvimportload_dotenvload_dotenv()mailer=sender_identities.NewSenderIdentity(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_identity(identity_id="12345"))Create a sender identityfrommailersendimportsender_identitiesfromdotenvimportload_dotenvload_dotenv()mailer=sender_identities.NewSenderIdentity(os.getenv('MAILERSEND_API_KEY'))print(mailer.create_identity(domain_id="123456",name="John Doe",email="email@domain.com",reply_to_email="reply@domain.com",reply_to_name="Doe John",add_note=True,personal_note="My awesome note",))Update a sender identityfrommailersendimportsender_identitiesfromdotenvimportload_dotenvload_dotenv()mailer=sender_identities.NewSenderIdentity(os.getenv('MAILERSEND_API_KEY'))print(mailer.update_identity(identity_id="123456",domain_id="123456",name="Abe Doe",email="email@mydomain.com",reply_to_email="reply@mydomain.com",reply_to_name="Doe Abe",add_note=False))Delete a sender identityfrommailersendimportsender_identitiesfromdotenvimportload_dotenvload_dotenv()mailer=sender_identities.NewSenderIdentity(os.getenv('MAILERSEND_API_KEY'))print(mailer.delete_identity(identity_id="123456"))API QuotaGet API Quotafrommailersendimportapi_quotafromdotenvimportload_dotenvload_dotenv()mailer=api_quota.NewApiQuota(os.getenv('MAILERSEND_API_KEY'))print(mailer.get_quota())TroubleshootingEmails not being sentPrint the output ofmailer.send()to view status code and errors.frommailersendimportemailsmailer=emails.NewEmail()mail_body={}print(mailer.send(mail_body))TestingTBDAvailable endpointsFeature groupEndpointAvailableActivityGET activity✅AnalyticsGET analytics✅Domains{GET, PUT, DELETE} domains✅EmailsPOST send✅MessagesGET messages✅Recipients{GET, DELETE} recipients✅Templates{GET, DELETE} templates✅Tokens{POST, PUT, DELETE} tokens✅Webhooks{GET, POST, PUT, DELETE} webhooks✅SMS Sending{POST} sms✅SMS Activity{GET} sms-activity✅SMS Phone numbers{GET, PUT, DELETE} sms-numbers✅SMS Recipients{GET, PUT} sms-recipients✅SMS Messages{GET} sms-messages✅SMS Webhooks{GET, POST, PUT, DELETE} sms-webhooks✅SMS Inbounds{GET, POST, PUT, DELETE} sms-inbounds✅Sender Identities{GET, POST, PUT, DELETE} identities✅API Quota{GET} api-quota✅If, at the moment, some endpoint is not available, please use other available tools to access it.Refer to official API docs for more info.Support and FeedbackIn 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 emailinfo@mailersend.comThe official documentation is athttps://developers.mailersend.comLicenseThe MIT License (MIT)