Ruby gem for sending emails through postmarkapp.com HTTP API
The gem is hosted at gemcutter. If you don’t have it, install it first:
sudo gem install gemcutter
Then
sudo gem install postmark
#!/usr/bin/env ruby require 'rubygems' require 'postmark' require 'tmail' Postmark.api_key = "your-api-key" message = TMail::Mail.new # make sure you have a sender signature with that email # from and to also accept arrays of emails. message.from = "[email protected]" message.to = "Sheldon Cooper <[email protected]>" message.subject = "Hi Sheldon!" message.content_type = "text/html" message.body = "Hello my friend!" # set custom headers at will. message["CUSTOM-HEADER"] = "my custom header value" # tag message message.tag = "my-tracking-tag" # set reply to if you need; also, you can pass array of emails. message.reply_to = "[email protected]" Postmark.send_through_postmark(message)
If you are using the Mail gem, you can also use Postmark as a delivery method like:
message = Mail.new message.delivery_method Mail::Postmark, {:api_key => “your-api-key”} message.deliver
You can retrieve various information about your server state using the Public bounces API - developer.postmarkapp.com/bounces
# get delivery stats Postmark.delivery_stats # json Postmark::Bounce.all # [ bounce, bounce ... ] bounce = Postmark::Bounce.find(bounce_id) # Bounce bounce.dump # string, containing raw SMTP data bounce.reactivate # reactivate hard bounce
To use SSL encryption when sending email configure the library as follows:
Postmark.secure = true
The gem relies on TMail or Mail for building the message. You will also need postmark account, server and sender signature set up to use it. If you plan using it in a rails project, check out the postmark-rails gem, which is meant to integrate with ActionMailer.
The plugin will try to use ActiveSupport Json if it is already included. If not, it will attempt using the built-in ruby Json library. You can also explicitly specify which one to be used, using
Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl is also supported.
Currently postmark API does not support attachments. For more information, check the docs at:
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history.
-
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Wildbit LLC. See LICENSE for details.