forked from ActiveCampaign/postmark-gem
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Postmark | ||
|
||
# | ||
# This fix is needed solely to support neat Rails 3 syntax to create emails. | ||
# That one: | ||
# | ||
# def invitation | ||
# mail( | ||
# :to => "someone@example.com", | ||
# :postmark_attachments => [File.open(...)] | ||
# ) | ||
# end | ||
# | ||
# That code will automatically put the file to Mail::OptionalField of the Mail::Message object | ||
# and will try to encode it before delivery. You are not supposed to store files in | ||
# such fields, so Mail will raise an exception. That's why before we actually perform a | ||
# delivery we have to remove the files from OptionalField to a regular @_attachments variable. | ||
# | ||
module AttachmentsFixForMail | ||
|
||
def self.included(base) | ||
base.class_eval do | ||
alias_method_chain :deliver, :postmark_hook | ||
end | ||
end | ||
|
||
def deliver_with_postmark_hook | ||
remove_postmark_attachments_from_standard_fields | ||
deliver_without_postmark_hook | ||
end | ||
|
||
private | ||
|
||
def remove_postmark_attachments_from_standard_fields | ||
field = self['POSTMARK-ATTACHMENTS'] | ||
return if field.nil? | ||
self.postmark_attachments = field.value | ||
self['POSTMARK-ATTACHMENTS'] = nil | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
module Mail | ||
class Postmark | ||
def initialize(values) | ||
self.settings = {:api_key => nil}.merge(values) | ||
end | ||
|
||
attr_accessor :settings | ||
|
||
def initialize(values) | ||
self.settings = { :api_key => nil }.merge(values) | ||
end | ||
|
||
def deliver!(mail) | ||
::Postmark.api_key = settings[:api_key] | ||
::Postmark.send_through_postmark(mail) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters