Sinatra
This guide shows you how to integrate Mailtrap with Sinatra and send emails using the Email API.
Before we start, you'll need to:
Send emails using Sinatra and Mailtrap
To integrate Mailtrap and send emails via Sinatra, copy the following script into your configuration:
require "sinatra"
require "mailtrap"
set :port, 5000
set :bind, "0.0.0.0"
get "/" do
content_type :json
mail = Mailtrap::Mail.from_content(
from: { name: 'Mailtrap Test', email: 'YOUR-EMAIL-HERE' },
to: [{ email: 'RECIPIENT-EMAIL-HERE' }],
subject: 'Hello World',
html: '<strong>it works!</strong>',
)
client = Mailtrap::Client.new(api_key: 'YOUR-MAILTRAP-API-KEY-HERE')
response = client.send(mail)
response.to_hash.to_json
endOnce you copy the script, make sure to:
Insert your Mailtrap API token in the
api_key:fieldEnter your email address in the
from:fieldEnter your recipient's email address in the
to:field
Last updated
Was this helpful?

