postmark 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +9 -0
- data/README.rdoc +38 -29
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/postmark.rb +21 -9
- data/lib/postmark/attachments_fix_for_mail.rb +43 -0
- data/lib/{mail/postmark.rb → postmark/handlers/mail.rb} +5 -3
- data/lib/postmark/{mail_message_extension.rb → message_extensions/mail.rb} +3 -7
- data/lib/postmark/message_extensions/shared.rb +33 -0
- data/lib/postmark/{tmail_mail_extension.rb → message_extensions/tmail.rb} +4 -10
- data/postmark.gemspec +9 -6
- metadata +10 -6
data/CHANGELOG.rdoc
ADDED
data/README.rdoc
CHANGED
@@ -4,10 +4,6 @@ Ruby gem for sending emails through http://postmarkapp.com HTTP API
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
The gem is hosted at gemcutter. If you don't have it, install it first:
|
8
|
-
|
9
|
-
sudo gem install gemcutter
|
10
|
-
Then
|
11
7
|
sudo gem install postmark
|
12
8
|
|
13
9
|
== Example
|
@@ -19,37 +15,48 @@ Then
|
|
19
15
|
require 'tmail'
|
20
16
|
|
21
17
|
Postmark.api_key = "your-api-key"
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
message
|
27
|
-
message.
|
28
|
-
message.
|
18
|
+
|
19
|
+
# Make sure you have a sender signature for every From email you specify.
|
20
|
+
# From can also accept array of addresses.
|
21
|
+
|
22
|
+
message = TMail::Mail.new
|
23
|
+
message.from = "leonard@bigbangtheory.com"
|
24
|
+
message.to = "Sheldon Cooper <sheldon@bigbangtheory.com>"
|
25
|
+
message.subject = "Hi Sheldon!"
|
29
26
|
message.content_type = "text/html"
|
30
|
-
message.body
|
31
|
-
|
27
|
+
message.body = "Hello my friend!"
|
28
|
+
|
29
|
+
# You can set customer headers if you like:
|
32
30
|
message["CUSTOM-HEADER"] = "my custom header value"
|
33
|
-
|
31
|
+
|
32
|
+
# Added a tag:
|
34
33
|
message.tag = "my-tracking-tag"
|
35
|
-
|
34
|
+
|
35
|
+
# Add attachments:
|
36
|
+
message.postmark_attachments = [File.open("/path"), File.open("/path")]
|
37
|
+
|
38
|
+
# Or specify a reply-to address (can also be an array of addresses):
|
36
39
|
message.reply_to = "penny@bigbangtheory.com"
|
37
40
|
|
38
41
|
Postmark.send_through_postmark(message)
|
39
42
|
|
40
43
|
If you are using the Mail gem, you can also use Postmark as a delivery method like:
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
message = Mail.new
|
46
|
+
message.delivery_method Mail::Postmark, {:api_key => "your-api-key"}
|
47
|
+
message.deliver
|
45
48
|
|
46
49
|
You can retrieve various information about your server state using the Public bounces API - http://developer.postmarkapp.com/bounces
|
47
50
|
|
48
|
-
#
|
49
|
-
Postmark.delivery_stats
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
# Get delivery stats: (JSON format)
|
52
|
+
Postmark.delivery_stats
|
53
|
+
|
54
|
+
# Get bounces information: (array of bounce objects)
|
55
|
+
Postmark::Bounce.all
|
56
|
+
|
57
|
+
# Find specific bounce by id:
|
58
|
+
bounce = Postmark::Bounce.find(bounce_id)
|
59
|
+
bounce.dump # string, containing raw SMTP data
|
53
60
|
bounce.reactivate # reactivate hard bounce
|
54
61
|
|
55
62
|
== Encryption
|
@@ -68,12 +75,6 @@ You can also explicitly specify which one to be used, using
|
|
68
75
|
|
69
76
|
Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl is also supported.
|
70
77
|
|
71
|
-
== Limitations
|
72
|
-
|
73
|
-
Currently postmark API does not support attachments. For more information, check the docs at:
|
74
|
-
|
75
|
-
http://developer.postmarkapp.com
|
76
|
-
|
77
78
|
== Note on Patches/Pull Requests
|
78
79
|
|
79
80
|
* Fork the project.
|
@@ -83,6 +84,14 @@ http://developer.postmarkapp.com
|
|
83
84
|
* Commit, do not mess with rakefile, version, or history.
|
84
85
|
* Send me a pull request. Bonus points for topic branches.
|
85
86
|
|
87
|
+
== Authors & Contributors
|
88
|
+
|
89
|
+
* Petyo Ivanov
|
90
|
+
* Ilya Sabanin
|
91
|
+
* Hristo Deshev
|
92
|
+
* Randy Schmidt
|
93
|
+
* Chris Williams
|
94
|
+
|
86
95
|
== Copyright
|
87
96
|
|
88
97
|
Copyright (c) 2010 Wildbit LLC. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gem.description = %Q{Ruby gem for sending emails through http://postmarkapp.com HTTP API. It relieas on TMail::Mail for message construction.}
|
10
10
|
gem.email = "underlog@gmail.com"
|
11
11
|
gem.homepage = "http://postmarkapp.com"
|
12
|
-
gem.authors = ["Petyo Ivanov"]
|
12
|
+
gem.authors = ["Petyo Ivanov", "Ilya Sabanin"]
|
13
13
|
gem.add_development_dependency "rspec"
|
14
14
|
gem.add_development_dependency "cucumber"
|
15
15
|
gem.add_dependency "tmail"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.9.0
|
data/lib/postmark.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
+
def require_local(file)
|
2
|
+
require File.join(File.dirname(__FILE__), 'postmark', file)
|
3
|
+
end
|
4
|
+
|
1
5
|
require 'net/http'
|
2
6
|
require 'net/https'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
require_local 'bounce'
|
9
|
+
require_local 'json'
|
10
|
+
require_local 'http_client'
|
11
|
+
require_local 'message_extensions/shared'
|
12
|
+
require_local 'message_extensions/tmail'
|
13
|
+
require_local 'message_extensions/mail'
|
14
|
+
require_local 'handlers/mail'
|
15
|
+
require_local 'attachments_fix_for_mail'
|
9
16
|
|
10
17
|
module Postmark
|
11
18
|
|
@@ -98,8 +105,8 @@ module Postmark
|
|
98
105
|
def delivery_stats
|
99
106
|
HttpClient.get("deliverystats")
|
100
107
|
end
|
101
|
-
|
102
|
-
|
108
|
+
|
109
|
+
protected
|
103
110
|
|
104
111
|
def convert_mail(message)
|
105
112
|
options = { "From" => message.from.to_s, "Subject" => message.subject }
|
@@ -114,6 +121,8 @@ module Postmark
|
|
114
121
|
options["Cc"] = message.cc.join(", ").to_s unless message.cc.nil?
|
115
122
|
|
116
123
|
options["Bcc"] = message.bcc.join(", ").to_s unless message.bcc.nil?
|
124
|
+
|
125
|
+
options["Attachments"] = message.postmark_attachments unless message.postmark_attachments.nil?
|
117
126
|
|
118
127
|
if reply_to = message['reply-to']
|
119
128
|
options["ReplyTo"] = reply_to.to_s
|
@@ -155,6 +164,8 @@ module Postmark
|
|
155
164
|
options["Cc"] = message['cc'].to_s unless message.cc.nil?
|
156
165
|
|
157
166
|
options["Bcc"] = message['bcc'].to_s unless message.bcc.nil?
|
167
|
+
|
168
|
+
options["Attachments"] = message.postmark_attachments unless message.postmark_attachments.nil?
|
158
169
|
|
159
170
|
if reply_to = message['reply-to']
|
160
171
|
options["ReplyTo"] = reply_to.to_s
|
@@ -197,9 +208,10 @@ module Postmark
|
|
197
208
|
bcc
|
198
209
|
subject
|
199
210
|
tag
|
211
|
+
attachment
|
200
212
|
]
|
201
213
|
end
|
202
|
-
|
214
|
+
|
203
215
|
end
|
204
216
|
|
205
217
|
self.response_parser_class = nil
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Postmark
|
2
|
+
|
3
|
+
#
|
4
|
+
# This fix is needed solely to support neat Rails 3 syntax to create emails.
|
5
|
+
# That one:
|
6
|
+
#
|
7
|
+
# def invitation
|
8
|
+
# mail(
|
9
|
+
# :to => "someone@example.com",
|
10
|
+
# :postmark_attachments => [File.open(...)]
|
11
|
+
# )
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# That code will automatically put the file to Mail::OptionalField of the Mail::Message object
|
15
|
+
# and will try to encode it before delivery. You are not supposed to store files in
|
16
|
+
# such fields, so Mail will raise an exception. That's why before we actually perform a
|
17
|
+
# delivery we have to remove the files from OptionalField to a regular @_attachments variable.
|
18
|
+
#
|
19
|
+
module AttachmentsFixForMail
|
20
|
+
|
21
|
+
def self.included(base)
|
22
|
+
base.class_eval do
|
23
|
+
alias_method_chain :deliver, :postmark_hook
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def deliver_with_postmark_hook
|
28
|
+
remove_postmark_attachments_from_standard_fields
|
29
|
+
deliver_without_postmark_hook
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def remove_postmark_attachments_from_standard_fields
|
35
|
+
field = self['POSTMARK-ATTACHMENTS']
|
36
|
+
return if field.nil?
|
37
|
+
self.postmark_attachments = field.value
|
38
|
+
header.fields.delete_if{|f| f.name == 'postmark-attachments'}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module Mail
|
2
2
|
class Postmark
|
3
|
-
def initialize(values)
|
4
|
-
self.settings = {:api_key => nil}.merge(values)
|
5
|
-
end
|
6
3
|
|
7
4
|
attr_accessor :settings
|
8
5
|
|
6
|
+
def initialize(values)
|
7
|
+
self.settings = { :api_key => nil }.merge(values)
|
8
|
+
end
|
9
|
+
|
9
10
|
def deliver!(mail)
|
10
11
|
::Postmark.api_key = settings[:api_key]
|
11
12
|
::Postmark.send_through_postmark(mail)
|
12
13
|
end
|
14
|
+
|
13
15
|
end
|
14
16
|
end
|
@@ -1,12 +1,7 @@
|
|
1
1
|
module Mail
|
2
2
|
class Message
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def tag=(value)
|
8
|
-
self["TAG"] = value
|
9
|
-
end
|
3
|
+
|
4
|
+
include Postmark::SharedMessageExtensions
|
10
5
|
|
11
6
|
def body_html
|
12
7
|
unless html_part.nil?
|
@@ -21,5 +16,6 @@ module Mail
|
|
21
16
|
text_part.body.to_s
|
22
17
|
end
|
23
18
|
end
|
19
|
+
|
24
20
|
end
|
25
21
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Postmark
|
2
|
+
module SharedMessageExtensions
|
3
|
+
|
4
|
+
def tag
|
5
|
+
self['TAG']
|
6
|
+
end
|
7
|
+
|
8
|
+
def tag=(value)
|
9
|
+
self['TAG'] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def postmark_attachments=(value)
|
13
|
+
@_attachments = value.is_a?(Array) ? value : [value]
|
14
|
+
end
|
15
|
+
|
16
|
+
def postmark_attachments
|
17
|
+
return if @_attachments.nil?
|
18
|
+
|
19
|
+
@_attachments.collect do |item|
|
20
|
+
if item.is_a?(Hash)
|
21
|
+
item
|
22
|
+
elsif item.is_a?(File)
|
23
|
+
{
|
24
|
+
"Name" => item.path.split("/")[-1],
|
25
|
+
"Content" => [ IO.read(item.path) ].pack("m"),
|
26
|
+
"ContentType" => "application/octet-stream"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -7,20 +7,14 @@
|
|
7
7
|
#
|
8
8
|
# This is a patch to try to resolve this
|
9
9
|
#
|
10
|
-
# just require '
|
10
|
+
# just require 'extensions/tmail'
|
11
11
|
# and every TMail::Mail object will have the .body_html method
|
12
12
|
#
|
13
13
|
|
14
14
|
module TMail
|
15
15
|
class Mail
|
16
|
-
|
17
|
-
|
18
|
-
self["TAG"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def tag=(value)
|
22
|
-
self["TAG"] = value
|
23
|
-
end
|
16
|
+
|
17
|
+
include Postmark::SharedMessageExtensions
|
24
18
|
|
25
19
|
#
|
26
20
|
# returs an String with just the html part of the body
|
@@ -86,7 +80,7 @@ module TMail
|
|
86
80
|
header = part["content-type"]
|
87
81
|
|
88
82
|
if part.multipart?
|
89
|
-
puts " --
|
83
|
+
puts " --multipart--"
|
90
84
|
part.parts.each_with_index do |part2, index2|
|
91
85
|
puts " part[#{index}][#{index2}]"
|
92
86
|
puts " content_type: #{part2.content_type}"
|
data/postmark.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{postmark}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.9.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Petyo Ivanov"]
|
12
|
-
s.date = %q{2010-09-
|
11
|
+
s.authors = ["Petyo Ivanov", "Ilya Sabanin"]
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.description = %q{Ruby gem for sending emails through http://postmarkapp.com HTTP API. It relieas on TMail::Mail for message construction.}
|
14
14
|
s.email = %q{underlog@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
".document",
|
22
22
|
".gitignore",
|
23
23
|
".rake_tasks",
|
24
|
+
"CHANGELOG.rdoc",
|
24
25
|
"Gemfile",
|
25
26
|
"Gemfile.lock",
|
26
27
|
"LICENSE",
|
@@ -31,16 +32,18 @@ Gem::Specification.new do |s|
|
|
31
32
|
"features/step_definitions/postmark_steps.rb",
|
32
33
|
"features/support/env.rb",
|
33
34
|
"init.rb",
|
34
|
-
"lib/mail/postmark.rb",
|
35
35
|
"lib/postmark.rb",
|
36
|
+
"lib/postmark/attachments_fix_for_mail.rb",
|
36
37
|
"lib/postmark/bounce.rb",
|
38
|
+
"lib/postmark/handlers/mail.rb",
|
37
39
|
"lib/postmark/http_client.rb",
|
38
40
|
"lib/postmark/json.rb",
|
39
|
-
"lib/postmark/
|
41
|
+
"lib/postmark/message_extensions/mail.rb",
|
42
|
+
"lib/postmark/message_extensions/shared.rb",
|
43
|
+
"lib/postmark/message_extensions/tmail.rb",
|
40
44
|
"lib/postmark/response_parsers/active_support.rb",
|
41
45
|
"lib/postmark/response_parsers/json.rb",
|
42
46
|
"lib/postmark/response_parsers/yajl.rb",
|
43
|
-
"lib/postmark/tmail_mail_extension.rb",
|
44
47
|
"postmark.gemspec",
|
45
48
|
"spec/bounce_spec.rb",
|
46
49
|
"spec/postmark_spec.rb",
|
metadata
CHANGED
@@ -4,17 +4,18 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 9
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.9.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Petyo Ivanov
|
13
|
+
- Ilya Sabanin
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-17 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- .document
|
68
69
|
- .gitignore
|
69
70
|
- .rake_tasks
|
71
|
+
- CHANGELOG.rdoc
|
70
72
|
- Gemfile
|
71
73
|
- Gemfile.lock
|
72
74
|
- LICENSE
|
@@ -77,16 +79,18 @@ files:
|
|
77
79
|
- features/step_definitions/postmark_steps.rb
|
78
80
|
- features/support/env.rb
|
79
81
|
- init.rb
|
80
|
-
- lib/mail/postmark.rb
|
81
82
|
- lib/postmark.rb
|
83
|
+
- lib/postmark/attachments_fix_for_mail.rb
|
82
84
|
- lib/postmark/bounce.rb
|
85
|
+
- lib/postmark/handlers/mail.rb
|
83
86
|
- lib/postmark/http_client.rb
|
84
87
|
- lib/postmark/json.rb
|
85
|
-
- lib/postmark/
|
88
|
+
- lib/postmark/message_extensions/mail.rb
|
89
|
+
- lib/postmark/message_extensions/shared.rb
|
90
|
+
- lib/postmark/message_extensions/tmail.rb
|
86
91
|
- lib/postmark/response_parsers/active_support.rb
|
87
92
|
- lib/postmark/response_parsers/json.rb
|
88
93
|
- lib/postmark/response_parsers/yajl.rb
|
89
|
-
- lib/postmark/tmail_mail_extension.rb
|
90
94
|
- postmark.gemspec
|
91
95
|
- spec/bounce_spec.rb
|
92
96
|
- spec/postmark_spec.rb
|