Installation
Or add to your Gemfile:
Basic Configuration
require 'mail'
# Configure Mail defaults
Mail.defaults do
delivery_method :smtp, {
address: 'smtp.lettermint.co',
port: 587,
user_name: 'lettermint',
password: 'your-api-token',
authentication: 'plain',
enable_starttls_auto: true
}
end
# Send email
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Test Email'
text_part do
body 'Hello! This is a test email.'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>Hello!</h1><p>This is a test email.</p>'
end
end
mail.deliver!
Advanced Features
Multiple Recipients
Attachments
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Document Attached'
body 'Please find the document attached.'
add_file '/path/to/document.pdf'
add_file filename: 'data.txt', content: 'Custom content'
end
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Custom Headers'
body 'Email with custom headers.'
header['X-Priority'] = '1'
header['X-Custom-Header'] = 'Custom Value'
end
Add metadata that will be included in webhook payloads:
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Order Confirmation'
body 'Your order has been confirmed.'
header['X-LM-Metadata-order_id'] = '12345'
header['X-LM-Metadata-customer_id'] = 'cust_789'
header['X-LM-Metadata-campaign'] = 'order_confirmation'
end
When using SMTP, metadata is passed via X-LM-Metadata-* headers. These are extracted by Lettermint and included in webhook payloads, but not added to the actual email sent to recipients.
Rails Integration
In config/environments/production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.lettermint.co',
port: 587,
user_name: 'lettermint',
password: ENV['LETTERMINT_API_TOKEN'],
authentication: 'plain',
enable_starttls_auto: true
}