MailerSend Ruby SDK
- Installation
- Setup
- Usage
- Email
- Send an email
- Add CC, BCC recipients
- Send a template-based email
- Personalization
- Bulk Email
- Send bulk email
- Get bulk email status
- Tokens
- Create a token
- Update a token
- Delete a token
- Send email with attachment
- Emails
- Get a list of emails
- Pagination
- Get a single email
- Activity
- Get a list of activities
- Analytics
- Activity data by date
- Opens by country
- Opens by user-agent name
- Opens by reading environment
- Inbound Routes
- Get a list of inbound routes
- Get a single inbound route
- Add an inbound route
- Update an inbound route
- Delete an inbound route
- Domains
- Get a list of domains
- Get a single domain
- Add a domain
- Delete a domain
- Get recipients for a domain
- Update domain settings
- Get DNS Records
- Get verification status
- DMARC Monitoring
- Get a list of monitors
- Create a monitor
- Update a monitor
- Delete a monitor
- Get aggregated reports
- Get IP-specific reports
- Get report sources
- Mark IP as favorite
- Remove IP from favorites
- Sender Identities
- Get a list of sender identities
- Get a single sender identity
- Get a single sender identity by email
- Add a sender identity
- Update a sender identity
- Update a sender identity by email
- Delete a sender identity
- Delete a sender identity by email
- Messages
- Get a list of messages
- Get info for a single message
- Scheduled Messages
- Get a list of scheduled messages
- Get a single scheduled message
- Delete a scheduled message
- Recipients
- Get recipients
- Get a single recipient
- Delete a recipient
- Suppressions
- Get recipients from a suppression list
- Add recipients to a suppression list
- Delete recipients from a suppression list
- Webhooks
- List webhooks
- Get a webhook
- Create a webhook
- Update a webhook
- Delete a webhook
- Templates
- Get templates
- Get a single template
- Delete template
- Email Verification
- Verify an email
- Get all email verification lists
- Get an email verification list
- Create an email verification list
- Verify an email list
- Get email verification list results
- WhatsApp
- Send a WhatsApp message
- Send a WhatsApp message with personalization
- WhatsApp Messages
- Get a list of WhatsApp messages
- Get a WhatsApp message
- WhatsApp Items
- Get a list of WhatsApp items
- Get a WhatsApp item
- WhatsApp Activities
- Get a list of WhatsApp activities
- WhatsApp Inbound Messages
- Get a list of WhatsApp inbound messages
- Get a WhatsApp inbound message
- WhatsApp Recipients
- Get a list of WhatsApp recipients
- Get a WhatsApp recipient
- WhatsApp Templates
- Get a list of WhatsApp templates
- Get a WhatsApp template
- SMS
- SMS Messages
- Get a list of SMS messages
- Get info on an SMS message
- SMS Activity
- Get a list of sms activities
- SMS Phone Numbers
- Get a list of SMS phone numbers
- Get an SMS phone number
- Update a single SMS phone number
- Delete an SMS phone number
- SMS Recipients
- Get a list of SMS recipients
- Get an SMS recipient
- Update a single SMS recipient
- SMS Inbounds
- Get a list of SMS inbound routes
- Get a single SMS inbound route
- Create an SMS inbound route
- Update an SMS inbound route
- Delete an SMS inbound route
- SMS Webhooks
- Get a list of SMS webhooks
- Get an SMS webhook
- Create an SMS webhook
- Update an SMS webhook
- Delete an SMS webhook
- Other endpoints
- Get API quota
- Email
- Support and Feedback
- License
Installation
Setup
gem install mailersend-rubyYou will have to initalize it in your Ruby file with require "mailersend-ruby".
Send an email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the email class
ms_email = Mailersend::Email.new(ms_client)
# Add parameters
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time")
ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
# Send the email
ms_email.sendAdd CC, BCC recipients
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the email class
ms_email = Mailersend::Email.new(ms_client)
# Add parameters
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
ms_email.add_cc("email" => "chris@parksandrec.com", "name" => "Chris")
ms_email.add_bcc("email" => "andy@parksandrec.com", "name" => "Andy")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time")
ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
# Send the email
ms_email.sendSend a template-based email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the email class
ms_email = Mailersend::Email.new(ms_client)
# Add parameters
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time")
ms_email.add_template_id(12415125)
# Optional: send the template in a specific language (language code).
# Only applies to template-based emails; ignored for raw html/text sends.
# Supported: de, en, es, fr, it, lt, nl, pl, pt-BR
ms_email.add_language("de")
# Send the email
ms_email.sendPersonalization
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the email class
ms_email = Mailersend::Email.new(ms_client)
# Add parameters
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time {{ test }}")
ms_email.add_text("{{ test }}Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
ms_email.add_html("<b>{{ test }}Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
personalization = {
email: 'ron@parksandrec.com',
data: {
test: 'Test Value'
}
}
ms_email.add_personalization(personalization)
ms_email.sendBulk Email
Send bulk email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_bulk_email = Mailersend::BulkEmail.new(ms_client)
ms_bulk_email.messages = [
{
'from' => {"email" => "april@parksandrec.com", "name" => "April"},
'to' => [{"email" => "ron@parksandrec.com", "name" => "Ron"}],
'subject' => "Time",
'text' => "Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.",
'html' => "<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>",
},
{
'from' => {"email" => "april@parksandrec.com", "name" => "April"},
'to' => [{"email" => "leslie@parksandrec.com", "name" => "Leslie"}],
'subject' => "Lorem Ipsum",
'text' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
'html' => "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
}
]
ms_bulk_email.sendGet bulk email status
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_bulk_email = Mailersend::BulkEmail.new(ms_client)
ms_bulk_email.get_bulk_status(bulk_email_id: 'yourbulkemailid')Tokens
Create a token
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_tokens = Mailersend::Tokens.new(ms_client)
ms_tokens.create(name: "Very nice token", scopes: %w[ email_full domains_read ], domain_id: "yourdomainid")Update a token
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_tokens = Mailersend::Tokens.new(ms_client)
ms_tokens.update(token_id: "d2220fx04", status: "paused")Delete a token
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_tokens = Mailersend::Tokens.new(ms_client)
ms_tokens.delete(token_id: "d2220fx04")Send email with attachment
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the email class
ms_email = Mailersend::Email.new(ms_client)
# Add parameters
ms_email.add_recipients("email" => "ron@parksandrec.com", "name" => "Ron")
ms_email.add_recipients("email" => "leslie@parksandrec.com", "name" => "Leslie")
ms_email.add_cc("email" => "chris@parksandrec.com", "name" => "Chris")
ms_email.add_bcc("email" => "andy@parksandrec.com", "name" => "Andy")
ms_email.add_from("email" => "april@parksandrec.com", "name" => "April")
ms_email.add_subject("Time")
ms_email.add_text("Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.")
ms_email.add_html("<b>Time is money, money is power, power is pizza, and pizza is knowledge. Let's go.</b>")
# You can add one or multiple attachments
ms.add_attachment(content: "/Users/Jerry/Desktop/doc.pdf", filename: "doc.pdf", disposition: "attachment")
ms.add_attachment(content: "/Users/Jerry/Desktop/pic.png", filename: "pic.png", disposition: "attachment")
ms_email.sendEmails
An email is the record of a message delivered to one recipient. Use these endpoints to build a searchable sending log, and to retrieve a single email together with its activity events.
Get a list of emails
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_emails = Mailersend::Emails.new(ms_client)
ms_emails.list(domain_id: "xxx2241ll", date_from: 1620643567, date_to: 1623321967, page: 1, limit: 50, status: %w[sent delivered], interaction: %w[opened])domain_id, date_from and date_to are required. Emails are returned newest first.
| Keyword argument | Type | Required | Details |
|---|---|---|---|
domain_id |
String |
yes | A domain that belongs to your account. An unknown domain returns 404. |
date_from |
Integer|String |
yes | Unix timestamp (1620643567) or datetime ("2015-10-01 00:00:00"), assumed UTC. Must be lower than date_to. |
date_to |
Integer|String |
yes | Unix timestamp or datetime. Must be higher than date_from and must not be in the future. |
limit |
Integer |
no | Min: 10, Max: 1000, Default: 25. |
page |
Integer |
no | Min: 1, Max: 100. See Pagination. |
status |
Array<String> |
no | Any of queued, sent, rejected, delivered. Sent as status[]. |
interaction |
Array<String> |
no | Any of opened, clicked, unsubscribed, complained, no_interaction. Sent as interaction[]. |
recipient_email |
String |
no | Exact, case-insensitive match. An unknown address returns 200 with an empty data array. |
message_id |
String |
no | Exact match. |
template_id |
String |
no | Exact match. |
subject |
String |
no | Min: 3 characters. Partial, case-insensitive match. |
tag |
String |
no | Exact match against a value in the email's tags array. |
Values inside status are combined with OR, values inside interaction are combined with OR, and the two filters
are combined with AND. Pass them as arrays (%w[sent delivered]) — the API rejects a scalar value with 422.
Note: This endpoint requires a token with one of the
activity_readoractivity_fullscopes, and is limited to 10 requests/minute shared withGET/v1/activity. Requests to either endpoint count against the same budget.
Each row in data describes one email. text and html are always null in list rows — retrieve the content with
single:
{
"data": [
{
"id": "5ee0b166b251345e407c9201",
"from": "no-reply@your-domain.com",
"to": "recipient@example.com",
"subject": "Your order has shipped",
"text": null,
"html": null,
"template_id": null,
"domain_id": "xxx2241ll",
"message_id": "5ee0b174ac2b8a35e407c9210",
"status": "delivered",
"tags": ["orders"],
"interaction": ["opened"],
"suppression_reason": null,
"created_at": "2021-05-10T10:06:14.482000Z",
"updated_at": "2021-05-10T10:06:18.114000Z",
"headers": [{ "name": "X-Custom", "value": "foo" }]
}
],
"links": {
"first": "https://api.mailersend.com/v1/emails?page=1",
"last": null,
"prev": null,
"next": "https://api.mailersend.com/v1/emails?page=2"
},
"meta": {
"current_page": 1,
"current_page_url": "https://api.mailersend.com/v1/emails?page=1",
"from": 1,
"path": "https://api.mailersend.com/v1/emails",
"per_page": 10,
"to": 3
}
}Pagination
Mailersend::Emails#list paginates by page number, the same way as
Mailersend::Activity#get. Pass page: to request a page, and read meta.current_page
to see which page you received.
The response carries no total and no last_page, and links.last is always null, so the number of pages is not
known up front. Walk the result set by requesting the next page until links.next is null:
require "mailersend-ruby"
require "json"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_emails = Mailersend::Emails.new(ms_client)
page = 1
loop do
response = ms_emails.list(domain_id: "xxx2241ll", date_from: 1620643567, date_to: 1623321967, limit: 100, page: page)
parsed_response = JSON.parse(response.body)
parsed_response['data'].each do |email|
puts email['id']
end
break if parsed_response['links']['next'].nil?
page += 1
endPass the same required parameters and filters on every page — changing them mid-walk restarts the result set. page
accepts values from 1 to 100 and limit from 10 to 1000; a value outside those ranges returns 422. To
retrieve a longer history, split it into several date_from/date_to windows instead of paging deeper.
Get a single email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_emails = Mailersend::Emails.new(ms_client)
ms_emails.single(email_id: "5ee0b166b251345e407c9201")Pass an id returned by list. The response contains everything a list row carries — plus
the text and html content, the recipient object, and an activity array of the events recorded for the email.
template_id is null when the email was not sent from a template.
Note:
activityevents are returned newest first and capped at 200 per email — useMailersend::Activity#getif you need the complete event history for a domain.deferredandsuppressedevents are only included if your plan has those features enabled, andsuppressedevents also carry asuppression_reason. Thejunkevent type is reported assoft_bounced. The array is returned even when content tracking is disabled for the domain, in which casehtmlandtextarenull.
Activity
Get a list of activities
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_activity = Mailersend::Activity.new(ms_client)
ms_activity.get(domain_id: "xxx2241ll", page: 3, limit: 5, date_from: 1620643567, date_to: 1623321967)Analytics
Activity data by date
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_analytics = Mailersend::Analytics.new(ms_client)
ms_analytics.date(date_from: 1620643567, date_to: 1623321967, events: %w[sent queued])Opens by country
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_analytics = Mailersend::Analytics.new(ms_client)
ms_analytics.country(date_from: 1620643567, date_to: 1623321967)Opens by user-agent name
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_analytics = Mailersend::Analytics.new(ms_client)
ms_analytics.ua_name(date_from: 1620643567, date_to: 1623321967)Opens by reading environment
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_analytics = Mailersend::Analytics.new(ms_client)
ms_analytics.ua_type(date_from: 1620643567, date_to: 1623321967)Inbound Routes
Get a list of inbound routes
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_inbound_routes = Mailersend::InboundRouting.new(ms_client)
ms_inbound_routes.get_inbound_routesGet a single inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_inbound_routes = Mailersend::InboundRouting.new(ms_client)
ms_inbound_routes.get_single_route(inbound_id: 'idofroute12412')Add an inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_inbound_routes = Mailersend::InboundRouting.new(ms_client)
ms_inbound_routes.settings =
{
'domain_id' => 'yourdomainid',
'name' => 'inbound_name',
'domain_enabled' => false,
'match_filter' => { 'type' => 'match_all' },
'forwards' => [{ 'type' => 'webhook', 'value' => 'https://example.com' }]
}
puts ms_inbound_routes.add_inbound_routeUpdate an inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_inbound_routes = Mailersend::InboundRouting.new(ms_client)
ms_inbound_routes.settings =
{
'domain_id' => 'yourdomainid',
'name' => 'inbound_updated',
'domain_enabled' => false,
'match_filter' => { 'type' => 'match_all' },
'forwards' => [{ 'type' => 'webhook', 'value' => 'https://example.com' }]
}
puts ms_inbound_routes.update_inbound_route(inbound_id: 'idofroute12412')Delete an inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_inbound_routes = Mailersend::InboundRouting.new(ms_client)
ms_inbound_routes.delete_route(inbound_id: 'idofroute12412')Domains
Get a list of domains
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.listGet a single domain
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.single(domain_id: "idofdomain12412")Add a domain
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.add(name: 'yourdomain')Delete a domain
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.delete(domain_id: "idofdomain12412")Get recipients for a domain
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.recipients(domain_id: "idofdomain12412")Update domain settings
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.settings(domain_id: "idofdomain12412", track_clicks: true, track_unsubscribe: false)Get DNS Records
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.dns(domain_id: "idofdomain12412")Get verification status
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_domains = Mailersend::Domains.new(ms_client)
ms_domains.verify(domain_id: "idofdomain12412")DMARC Monitoring
Get a list of monitors
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.listCreate a monitor
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.create(domain_id: "idofdomain12412")Update a monitor
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.update(monitor_id: "idofmonitor12412", wanted_dmarc_record: "v=DMARC1; p=reject;")Delete a monitor
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.delete(monitor_id: "idofmonitor12412")Get aggregated reports
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.report(monitor_id: "idofmonitor12412")Get IP-specific reports
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.report_by_ip(monitor_id: "idofmonitor12412", ip: "1.2.3.4")Get report sources
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.report_sources(monitor_id: "idofmonitor12412")Mark IP as favorite
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.add_favorite(monitor_id: "idofmonitor12412", ip: "1.2.3.4")Remove IP from favorites
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_dmarc = Mailersend::DmarcMonitoring.new(ms_client)
ms_dmarc.remove_favorite(monitor_id: "idofmonitor12412", ip: "1.2.3.4")Sender Identities
Get a list of sender identities
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.listGet a single sender identity
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.single(identity_id: 'idofidentity123')Get a single sender identity by email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.single_by_email(email: 'example@email.com')Add a sender identity
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.add(domain_id: 'idofdomain12412', name: 'yourname', email: 'youremail')Update a sender identity
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.update(identity_id: 'idofidentity123', reply_to_email: 'replyemail', reply_to_name: 'replyname')Update a sender identity by email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.update_by_email(email: 'example@email.com', reply_to_email: 'replyemail', reply_to_name: 'replyname')Delete a sender identity
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.delete(identity_id: 'idofidentity123')Delete a sender identity by email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_sender_identity = Mailersend::SenderIdentity.new(ms_client)
ms_sender_identity.delete_by_email(email: 'example@email.com')Messages
Get a list of messages
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_messages = Mailersend::Messages.new(ms_client)
ms_messages.list(page: 1, limit: 10)Get info for a single message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_messages = Mailersend::Messages.new(ms_client)
ms_messages.single(message_id: "mess11454")Scheduled Messages
Get a list of scheduled messages
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_scheduled_messages = Mailersend::ScheduledMessages.new(ms_client)
ms_scheduled_messages.get_listGet a single scheduled message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_scheduled_messages = Mailersend::ScheduledMessages.new(ms_client)
ms_scheduled_messages.get_single(message_id: 'mess11454')Delete a scheduled message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_scheduled_messages = Mailersend::ScheduledMessages.new(ms_client)
ms_scheduled_messages.delete(message_id: 'mess11454')Recipients
Get recipients
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_recipients = Mailersend::Recipients.new(ms_client)
ms_recipients.list(page: 1, limit: 10)Get a single recipient
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_recipients = Mailersend::Recipients.new(ms_client)
ms_recipients.single(recipient_id: "id124")Delete a recipient
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_recipients = Mailersend::Recipients.new(ms_client)
ms_recipients.delete(recipient_id: "id124")Suppressions
Get recipients from a suppression list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_suppressions = Mailersend::Suppressions.new(ms_client)
// List from Blocklist
ms_suppressions.get_from_blocklist(domain_id: "xxx2241ll")
// List from Hard Bounces
ms_suppressions.get_hard_bounces(domain_id: "xxx2241ll")
// List from Spam Complaints
ms_suppressions.get_spam_complaints(domain_id: "xxx2241ll")
// List from Unsubscribers
ms_suppressions.get_unsubscribes(domain_id: "xxx2241ll")Add recipients to a suppression list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_suppressions = Mailersend::Suppressions.new(ms_client)
// Add Recipient to Block List using recipients
ms_suppressions.add_to_blocklist(domain_id: "xxx2241ll", recipients: ["blocked@client.com"])
// Add Recipient to Block List using patterns
ms_suppressions.add_to_blocklist(domain_id: "xxx2241ll", patterns: ["*@client.com"])
// Add Recipient to Hard Bounces
ms_suppressions.add_to_hard_bounces(domain_id: "xxx2241ll", recipients: ["bounced@client.com"])
// Add Recipient to Spam Complaints
ms_suppressions.add_to_spam_complaints(domain_id: "xxx2241ll", recipients: ["bounced@client.com"])
// Add Recipient to Unsubscribes
ms_suppressions.add_to_unsubscribers(domain_id: "xxx2241ll", recipients: ["bounced@client.com"])Delete recipients from a suppression list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_suppressions = Mailersend::Suppressions.new(ms_client)
// Delete from Block List
ms_suppressions.delete_from_blocklist(domain_id: 'yourdomainid', ids: ["xxx2241ll"])
// Delete from Hard Bounces
ms_suppressions.delete_from_hard_bounces(domain_id: 'yourdomainid', ids: ["xxx2241ll"])
// Delete from Spam Complaints
ms_suppressions.delete_from_spam_complaints(domain_id: 'yourdomainid', ids: ["xxx2241ll"])
// Delete from Unsubscribes
ms_suppressions.delete_from_unsubscribers(domain_id: 'yourdomainid', ids: ["xxx2241ll"])Webhooks
List webhooks
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_webhooks = Mailersend::Webhooks.new(ms_client)
ms_webhooks.list(domain_id: "xxx2241ll")Get a webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_webhooks = Mailersend::Webhooks.new(ms_client)
ms_webhooks.single(webhook_id: "zzz2241ll")Create a webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_webhooks = Mailersend::Webhooks.new(ms_client)
ms_webhooks.create(domain_id: "xxx2241ll", url: "https://domain.com/hook", name: "Webhook", events: ["activity.sent", "activity.delivered"], enabled: true)Update a webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_webhooks = Mailersend::Webhooks.new(ms_client)
ms_webhooks.update(webhook_id: "zzz2241ll", enabled: false)Delete a webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_webhooks = Mailersend::Webhooks.new(ms_client)
ms_webhooks.delete(webhook_id: "zzz2241ll")Templates
Get templates
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_templates = Mailersend::Templates.new(ms_client)
ms_templates.list(domain_id: "aax455lll", page: 1, limit: 10)Get a single template
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_templates = Mailersend::Templates.new(ms_client)
ms_templates.single(template_id: "id124")Delete template
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_templates = Mailersend::Templates.new(ms_client)
ms_templates.delete(template_id: "id124")Email Verification
Verify an email
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.verify_an_email(email: 'example@email.com')Get all email verification lists
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.list(page: 1, limit: 10)Get an email verification list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.get_single_list(email_verification_id: 'your-email-verification-id')Create an email verification list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.create_a_list(name: "name-your-list", emails: ["example@email.com"])Verify an email list
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.verify_a_list(email_verification_id: 'your-email-verification-id')Get email verification list results
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
ms_email_verification = Mailersend::EmailVerification.new(ms_client)
ms_email_verification.get_list_results(email_verification_id: 'your-email-verification-id')SMS
Send an SMS
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS class
ms_sms = Mailersend::SMS.new(ms_client)
# Add parameters
ms_sms.add_from('your-number')
ms_sms.add_to('client-number')
ms_sms.add_text('This is the message content')
personalization = {
phone_number: 'client-number',
data: {
test: 'Test Value'
}
}
ms_sms.add_personalization(personalization)
# Send the SMS
ms_sms.sendSMS Messages
Get a list of SMS messages
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Messages class
ms_sms_messages = Mailersend::SMSMessages.new(ms_client)
# Add parameters
ms_sms_messages.list(page: 1, limit: 10)Get info on an SMS message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Messages class
ms_sms_messages = Mailersend::SMSMessages.new(ms_client)
# Add parameters
ms_sms_messages.get_single_route(sms_message_id: 'your-sms-message-id')SMS Activity
Get a list of sms activities
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_activity = Mailersend::SMSActivity.new(ms_client)
# Add parameters
ms_sms_activity.list(page: 1, limit: 10)SMS phone numbers
Get a list of SMS phone numbers
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_number = Mailersend::SMSNumber.new(ms_client)
# Add parameters
ms_sms_number.list(page: 1, limit: 10)Get an SMS phone number
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_number = Mailersend::SMSNumber.new(ms_client)
# Add parameters
ms_sms_number.get(sms_number_id: 'your-sms-number-id')Update a single SMS phone number
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_number = Mailersend::SMSNumber.new(ms_client)
# Add parameters
ms_sms_number.update(sms_number_id: 'your-sms-number-id', paused: false)Delete an SMS phone number
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_number = Mailersend::SMSNumber.new(ms_client)
# Add parameters
ms_sms_number.delete(sms_number_id: 'your-sms-number-id')SMS recipients
Get a list of SMS recipients
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new(ms_client)
# Add parameters
ms_sms_recipient.list(page: 1, limit: 10)Get an SMS recipient
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new(ms_client)
# Add parameters
ms_sms_recipient.get(sms_recipient_id: 'your-sms-recipient-id')Update a single SMS recipient
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Recipient class
ms_sms_recipient = Mailersend::SMSRecipient.new(ms_client)
# Add parameters
ms_sms_recipient.update(sms_recipient_id: 'your-sms-recipient-id', status: 'opt_out')SMS Inbounds
Get a list of SMS inbound routes
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new(ms_client)
ms_sms_inbounds.listGet a single SMS inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new(ms_client)
# Add parameters
ms_sms_inbounds.get_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')Create an SMS inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new(ms_client)
# Add parameters
ms_sms_inbounds.settings =
{
'forward_url' => 'https://your-forward-url',
'name' => 'name',
'events' => ['sms.sent', 'sms.delivered'],
'sms_number_id' => 'your-sms-number-id'
}
puts ms_sms_inbounds.add_sms_inbound_routeUpdate an SMS inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new(ms_client)
# Add parameters
ms_sms_inbounds.settings =
{
'forward_url' => 'https://your-forward-url',
'name' => 'name',
'events' => ['sms.sent', 'sms.delivered'],
'sms_number_id' => 'your-sms-number-id'
}
puts ms_sms_inbounds.update_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')Delete an SMS inbound route
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new(ms_client)
# Add parameters
ms_sms_inbounds.delete_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')SMS Webhooks
Get a list of SMS webhooks
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Webhooks class
ms_sms_webhooks = Mailersend::SMSWebhooks.new(ms_client)
# Add parameters
ms_sms_webhooks.list(sms_number_id: 'your-sms-number-id')Get an SMS webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Webhooks class
ms_sms_webhooks = Mailersend::SMSWebhooks.new(ms_client)
# Add parameters
ms_sms_webhooks.get_sms_webhook_route(sms_webhook_id: 'your-sms-webhook-id')Create an SMS webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Webhooks class
ms_sms_webhooks = Mailersend::SMSWebhooks.new(ms_client)
# Add parameters
ms_sms_webhooks.settings =
{
'sms_number_id' => 'your-sms-number-id',
'name' => 'your-name',
'url' => 'https://your-url.com',
'events' => ['sms.sent', 'sms.delivered']
}
puts ms_sms_webhooks.add_sms_webhook_routeUpdate an SMS webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Webhooks class
ms_sms_webhooks = Mailersend::SMSWebhooks.new(ms_client)
# Add parameters
ms_sms_webhooks.settings =
{
'sms_number_id' => 'your-sms-number-id',
'name' => 'your-name',
'url' => 'https://your-url.com',
'events' => ['sms.sent', 'sms.delivered']
}
puts ms_sms_webhooks.update_sms_webhook_route(sms_webhook_id: 'your-sms-webhook-id')Delete an SMS webhook
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the SMS Webhooks class
ms_sms_webhooks = Mailersend::SMSWebhooks.new(ms_client)
# Add parameters
ms_sms_webhooks.delete_sms_webhook_route(sms_webhook_id: 'your-sms-webhook-id')Send a WhatsApp message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Initialize the WhatsApp class
ms_whatsapp = Mailersend::WhatsApp.new(ms_client)
ms_whatsapp.add_from('your-number')
ms_whatsapp.add_to('recipient-number')
ms_whatsapp.add_template_id('your-template-id')
ms_whatsapp.sendSend a WhatsApp message with personalization
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Initialize the WhatsApp class
ms_whatsapp = Mailersend::WhatsApp.new(ms_client)
ms_whatsapp.add_from('your-number')
ms_whatsapp.add_to('recipient-number')
ms_whatsapp.add_template_id('your-template-id')
personalization = {
to: 'recipient-number',
data: {
header: ['John'],
body: ['order #1234', 'tomorrow'],
buttons: ['orders/1234']
}
}
ms_whatsapp.add_personalization(personalization)
ms_whatsapp.sendWhatsApp Messages
Get a list of WhatsApp messages
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Messages class
ms_whatsapp_messages = Mailersend::WhatsAppMessages.new(ms_client)
# Add parameters
ms_whatsapp_messages.list(
whatsapp_account_id: 'your-whatsapp-account-id',
from: '15550001234',
template_id: 'your-template-id',
date_from: 1791936000,
date_to: 1792022400,
page: 1,
limit: 25
)Get a WhatsApp message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Messages class
ms_whatsapp_messages = Mailersend::WhatsAppMessages.new(ms_client)
# Add parameters
ms_whatsapp_messages.get(whatsapp_message_id: 'your-whatsapp-message-id')WhatsApp Items
Get a list of WhatsApp items
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Items class
ms_whatsapp_items = Mailersend::WhatsAppItems.new(ms_client)
# Add parameters
ms_whatsapp_items.list(
recipient: '48600000002',
whatsapp_message_id: 'your-whatsapp-message-id',
status: %w[delivered read],
whatsapp_account_id: 'your-whatsapp-account-id',
from: '15550001234',
template_id: 'your-template-id',
date_from: 1791936000,
date_to: 1792022400,
page: 1,
limit: 25
)Get a WhatsApp item
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Items class
ms_whatsapp_items = Mailersend::WhatsAppItems.new(ms_client)
# Add parameters
ms_whatsapp_items.get(whatsapp_item_id: 'your-whatsapp-item-id')WhatsApp Activities
Get a list of WhatsApp activities
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Activities class
ms_whatsapp_activities = Mailersend::WhatsAppActivities.new(ms_client)
# Add parameters
ms_whatsapp_activities.list(
whatsapp_item_id: 'your-whatsapp-item-id',
whatsapp_message_id: 'your-whatsapp-message-id',
recipient: '48600000001',
type: %w[delivered read],
date_from: 1791936000,
date_to: 1792022400,
page: 1,
limit: 25
)WhatsApp Inbound Messages
Get a list of WhatsApp inbound messages
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Inbound Messages class
ms_whatsapp_inbound_messages = Mailersend::WhatsAppInboundMessages.new(ms_client)
# Add parameters
ms_whatsapp_inbound_messages.list(
whatsapp_account_id: 'your-whatsapp-account-id',
from: '48600000001',
type: %w[text image],
date_from: 1791936000,
date_to: 1792022400,
page: 1,
limit: 25
)Get a WhatsApp inbound message
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Inbound Messages class
ms_whatsapp_inbound_messages = Mailersend::WhatsAppInboundMessages.new(ms_client)
# Add parameters
ms_whatsapp_inbound_messages.get(whatsapp_inbound_message_id: 'your-whatsapp-inbound-message-id')WhatsApp Recipients
Get a list of WhatsApp recipients
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Recipient class
ms_whatsapp_recipient = Mailersend::WhatsAppRecipient.new(ms_client)
# Add parameters
ms_whatsapp_recipient.list(status: 'active', phone_number: '48600000001', page: 1, limit: 25)Get a WhatsApp recipient
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Recipient class
ms_whatsapp_recipient = Mailersend::WhatsAppRecipient.new(ms_client)
# Add parameters
ms_whatsapp_recipient.get(whatsapp_recipient_id: 'your-whatsapp-recipient-id')WhatsApp Templates
Get a list of WhatsApp templates
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Templates class
ms_whatsapp_templates = Mailersend::WhatsAppTemplates.new(ms_client)
# Add parameters
ms_whatsapp_templates.list(
whatsapp_account_id: 'your-whatsapp-account-id',
status: 'approved',
category: 'UTILITY',
language: 'en_US',
page: 1,
limit: 25
)Get a WhatsApp template
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the WhatsApp Templates class
ms_whatsapp_templates = Mailersend::WhatsAppTemplates.new(ms_client)
# Add parameters
ms_whatsapp_templates.get(whatsapp_template_id: 'your-whatsapp-template-id')Other endpoints
Get API quota
require "mailersend-ruby"
ms_client = Mailersend::Client.new('your_mailersend_token')
# Intialize the API Quota class
ms_api_quota = Mailersend::APIQuota.new(ms_client)
# Add parameters
ms_api_quota.get_api_quotaTesting
bundle i
bundle exec rspec spec/*_rspec.rbTo run tests you would need to install gems using bundle and then run rspec via bundle to run all tests. The fixtures for the test have been recorded using vcr and are available in the ./fixtures directory.
Support and Feedback
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