Ruby
Integrate Mailtrap with Ruby apps and projects for email sending using SDK, SMTP, or RESTful API
Last updated
Was this helpful?
Was this helpful?
gem 'mailtrap'bundle install# place this code in config/environments/production.rb:
config.action_mailer.delivery_method = :mailtrap
# then set the MAILTRAP_API_KEY environment variable
# using your hosting solution.require 'mailtrap'
client = Mailtrap::Client.new(api_key: 'your-api-token')
mail = Mailtrap::Mail::FromTemplate.new(
from: { email: 'hello@example.com', name: 'Mailtrap Test' },
to: [{ email: 'recipient@example.com' }],
template_uuid: 'template-uuid',
template_variables: {
'user_name' => 'John Doe'
}
)
# Or send a simple email
mail = {
from: { email: 'hello@example.com', name: 'Mailtrap Test' },
to: [{ email: 'recipient@example.com' }],
subject: 'Hello from Mailtrap!',
text: 'Welcome to Mailtrap Email Sending!',
html: '<p>Welcome to <strong>Mailtrap</strong> Email Sending!</p>'
}
response = client.send(mail)
puts response