-
Notifications
You must be signed in to change notification settings - Fork 71
Using Postmark with Mail library
Igor Balos edited this page Oct 1, 2018
·
6 revisions
You can use Postmark with the mail gem.
gem install mail
Make sure you have a sender signature for
every From
email address you specify.
To send a Mail::Message
via Postmark you’ll need to specify Mail::Postmark
as
a delivery method for the message:
message = Mail.new do
# ...
delivery_method Mail::Postmark, api_token: 'your-server-token'
end
Delivery method accepts all options supported by Postmark::ApiClient
documented above. A new instance of Postmark::ApiClient
is created every time
you deliver a message to preserve thread safety.
If you would prefer to use Postmark as the default delivery method for all
Mail::Message
instances, you can call Mail.defaults
method during the initialization
step of your app:
Mail.defaults do
delivery_method Mail::Postmark, api_token: 'your-server-token'
end
require 'rubygems'
require 'postmark'
require 'mail'
require 'json'
message = Mail.new do
from '[email protected]'
to 'Leonard Hofstadter <[email protected]>'
subject 'Re: Come on, Sheldon. It will be fun.'
body 'That\'s what you said about the Green Lantern movie. You' \
'were 114 minutes of wrong.'
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
end
message.deliver
# => #<Mail::Message:70355890541720, Multipart: false, Headers: <From: [email protected]>, <To: [email protected]>, <Message-ID: e439fec0-4c89-475b-b3fc-eb446249a051>, <Subject: Re: Come on, Sheldon. It will be fun.>>
For additional information about the capabilities of the Postmark API, see Postmark Developers Documentation.
- Email sending
- Test email sending
- Bounces
- Templates
- Templates push
- Server
- Servers
- Message Streams
- Webhooks
- Messages
- Domains
- Sender Signatures
- Stats
- Trigger Tags
- Suppressions
- Data Removals
- Trigger Inbound Rules
- Parsing Inbound
- Using Postmark with Mail library
- Accessing Postmark Message ID
- Error Handling
- Integration Testing
- Troubleshooting
- Known issues and how to resolve them