Mailtrap Sinatra Integration
Mailtrap can be integrated with Sinatra apps and projects for email sending, find out how to do it.
Before we start, you’ll need to:
Send emails using Sinatra and Mailtrap
To integrate Mailtrap and send emails via Sinatra, simply copy/paste 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
end
Once you copy the script, make sure to insert your Mailtrap API token in the api_key: field and enter your and your recipient's emails in the from: and to: fields.
Note: To learn more about API integration, click here.