Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Mandrill support #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ gem 'configatron'
gem 'pry'
gem 'rest-client'
gem 'mail'
gem 'mandrill-api'

gem 'gmail-britta', :git => 'git://github.com/bkrausz/gmail-britta.git', :ref => 'ced6355443fe2b99f6414b2da096c70a38b23f98'

group :development, :test do
gem 'mocha'
gem 'rerun'
end
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ GEM
bson_ext (1.11.1)
bson (~> 1.11.1)
builder (3.2.2)
celluloid (0.16.0)
timers (~> 4.0.0)
chalk-config (0.2.1)
configatron (~> 4.4)
chalk-log (0.1.2)
Expand All @@ -37,9 +39,11 @@ GEM
configatron (4.4.1)
einhorn (0.6.3)
erubis (2.7.0)
excon (0.45.4)
extlib (0.9.16)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
google-api-client (0.7.1)
addressable (>= 2.3.2)
autoparse (>= 0.3.3)
Expand All @@ -52,18 +56,26 @@ GEM
signet (>= 0.5.0)
uuidtools (>= 2.1.0)
haml (3.1.8)
hitimes (1.2.2)
i18n (0.6.11)
json (1.8.1)
jwt (1.2.0)
launchy (2.4.3)
addressable (~> 2.3)
listen (2.10.1)
celluloid (~> 0.16.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
little-plugger (1.1.3)
logging (1.8.2)
little-plugger (>= 1.1.3)
multi_json (>= 1.8.4)
lspace (0.13)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mandrill-api (1.0.53)
excon (>= 0.16.0, < 1.0)
json (>= 1.7.7, < 2.0)
metaclass (0.0.4)
method_source (0.8.2)
mime-types (2.4.3)
Expand Down Expand Up @@ -96,6 +108,11 @@ GEM
rack_csrf (2.5.0)
rack (>= 1.1.0)
rake (10.4.0)
rb-fsevent (0.9.6)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rerun (0.10.0)
listen (~> 2.7, >= 2.7.3)
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
Expand All @@ -113,6 +130,8 @@ GEM
thread (0.1.4)
thread_safe (0.3.4)
tilt (1.4.1)
timers (4.0.4)
hitimes
tzinfo (1.2.2)
thread_safe (~> 0.1)
uuidtools (2.1.5)
Expand All @@ -130,13 +149,18 @@ DEPENDENCIES
gmail-britta!
google-api-client
mail
mandrill-api
mocha
mongo_mapper
pry
puma
rack-flash3
rack_csrf
rake
rerun
rest-client
sinatra
thread

BUNDLED WITH
1.10.6
18 changes: 18 additions & 0 deletions bin/test_mandrill.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require File.expand_path('../lib/gaps', File.dirname(__FILE__))

Gaps.init

Gaps::Email.send_email(
:to => configatron.notify.to,
:from => configatron.notify.from,
:subject => "[gaps] Testing email",
:body => <<EOF
A new mailing list was just created:

You can subscribe to this list at:

You can view more details about this group at:

EOF
)
25 changes: 23 additions & 2 deletions lib/gaps/email.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'restclient'
require 'mail'
require 'mandrill'

module Gaps
module Email
Expand All @@ -9,8 +10,28 @@ def self.send_email(opts)
mail = Mail.new(opts)

if configatron.notify.send_email
mail.delivery_method :sendmail
mail.deliver!
if configatron.notify.provider == "mandrill"
begin
mandrill = Mandrill::API.new configatron.notify.api_key
message = {
"from_email"=>opts[:from],
"text"=>opts[:body],
"to"=> [{"email"=>opts[:to],
"type"=>"to"}],
"subject"=>opts[:subject],
}
async = false
result = mandrill.messages.send message

rescue Mandrill::Error => e
# Mandrill errors are thrown as exceptions
log.error "A mandrill error occurred: #{e.class} - #{e.message}"
raise
end
else
mail.delivery_method :sendmail
mail.deliver!
end
else
log.info("Would have sent", email: mail.to_s)
end
Expand Down
10 changes: 7 additions & 3 deletions site.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ info:
notify:
# Whether to send an email notifying people when a new list is
# created. If disabled, will instead just print the email to the
# console. (Note you must have a functioning sendmail setup for this
# to work; a TODO is to integrate with an email provider like
# Mailgun.)
# console.
# Can use sendmail or Mandrill to send emails
send_email: false
# Default provider
provider: sendmail
# Mandrill - need to include and API key
#provider: mandrill
#api_key: xxxxxxxx
# What email address to notify.
to: [email protected]
# What email address to send from. In Stripe's email transparency
Expand Down