postmark 0.9.15 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,13 @@
1
1
  = Changelog
2
2
 
3
+ == 0.9.16
4
+
5
+ * Thread-safe HTTP requests
6
+ * Fixed inproper method of ActiveSupport::JSON detection
7
+ * Removed unexpected ActiveSupport dependency from Postmark::SharedMessageExtensions#postmark_attachments= method
8
+ * Used Markdown to format README
9
+ * Updated README
10
+
3
11
  == 0.9.15
4
12
 
5
13
  * Save a received MessageID in message headers.
data/Gemfile CHANGED
@@ -2,10 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in postmark.gemspec
4
4
  gemspec
5
-
6
-
7
- group :development do
8
-
9
- end
10
-
11
-
@@ -0,0 +1,329 @@
1
+ # Postmark Gem
2
+
3
+ This gem is an official wrapper for [Postmark HTTP API](http://postmarkapp.com). Use it to send emails and retrieve info about bounces.
4
+
5
+ ## Getting Started
6
+
7
+ ### Install the gem
8
+
9
+ ``` bash
10
+ gem install postmark
11
+ ```
12
+
13
+ ### Install [Mail](http://rubygems.org/gems/mail) library
14
+
15
+ In addition to the `postmark` gem you also need to install `mail` gem.
16
+
17
+ ``` bash
18
+ gem install mail
19
+ ```
20
+
21
+ You can also use the gem with `tmail` library. This is not recommended for any
22
+ new projects, but may be useful for legacy Ruby 1.8.7 projects.
23
+
24
+ ### Get Postmark API key
25
+
26
+ In order to send emails using Postmark ruby gem, you will need a
27
+ [Postmark](http://postmarkapp.com) account. If you don't have one please
28
+ register at https://postmarkapp.com/sign_up.
29
+
30
+ If you didn't create any servers yet, please create one, proceed to
31
+ `Credentials` tab and copy an API key. API keys should be frequently rotated for
32
+ security reasons.
33
+
34
+ ## Using with [Mail](http://rubygems.org/gems/mail) library
35
+
36
+ Make sure you have a [sender signature](https://postmarkapp.com/signatures) for
37
+ every From email you specify. From can also accept array of addresses.
38
+
39
+ ### Plain text message
40
+
41
+ ``` ruby
42
+ require 'rubygems'
43
+ require 'postmark'
44
+ require 'mail'
45
+ require 'json'
46
+
47
+ message = Mail.new do
48
+ from 'sheldon@bigbangtheory.com'
49
+ to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
50
+ subject 'Re: Come on, Sheldon. It will be fun.'
51
+ body 'That\'s what you said about the Green Lantern movie. You' \
52
+ 'were 114 minutes of wrong.'
53
+
54
+ delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
55
+ end
56
+
57
+ message.deliver
58
+ # => #<Mail::Message:70355890541720, Multipart: false, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: e439fec0-4c89-475b-b3fc-eb446249a051>, <Subject: Re: Come on, Sheldon. It will be fun.>>
59
+ ```
60
+
61
+ ### HTML message
62
+
63
+ ``` ruby
64
+ require 'rubygems'
65
+ require 'postmark'
66
+ require 'mail'
67
+ require 'json'
68
+
69
+ message = Mail.new do
70
+ from 'sheldon@bigbangtheory.com'
71
+ to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
72
+ subject 'Re: What, to you, is a large crowd?'
73
+
74
+ content_type 'text/html; charset=UTF-8'
75
+ body '<p>Any group big enough to trample me to death. General ' \
76
+ 'rule of thumb is 36 adults or 70 children.</p>'
77
+
78
+ delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
79
+ end
80
+
81
+ message.deliver
82
+ # => #<Mail::Message:70355902117460, Multipart: false, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: 3a9370a2-6c24-4304-a03c-320a54cc59f7>, <Subject: Re: What, to you, is a large crowd?>, <Content-Type: text/html; charset=UTF-8>>
83
+ ```
84
+
85
+ ### Message with attachments
86
+
87
+ You can use postmark gem to send messages with attachments. Please note that:
88
+
89
+ * Only allowed file types can be sent as attachments. The message will be rejected (or you will get an SMTP API bounce if using SMTP) with a description of the rejected file, if you try to send a file with a disallowed extension.
90
+ * Attachment size can be 10 MB at most. That means you can send three attachments weighing at three megabytes each, but you won't be able to send a single 11MB attachment. Don't worry about base64 encoding making your data larger than it really is. Attachment size is calculated using the real binary data (after base64-decoding it).
91
+ * Many applications can get away with sending email as a response to a user action and do that right in the same web request handler. Sending attachments changes that. Message size can and will get bigger and the time to submit it to the Postmark servers will get longer. That is why we recommend that you send email with attachments from a background job. Your users will love you for that!
92
+
93
+ Check out our [special documentation section](http://developer.postmarkapp.com/developer-build.html#attachments)
94
+ for detailed information.
95
+
96
+ ``` ruby
97
+ require 'rubygems'
98
+ require 'postmark'
99
+ require 'mail'
100
+ require 'json'
101
+
102
+ message = Mail.new do
103
+ from 'leonard@bigbangtheory.com'
104
+ to 'Dr. Sheldon Cooper <sheldon@bigbangtheory.com>'
105
+ subject 'Have you seen these pictures of yours?'
106
+ body 'You look like a real geek!'
107
+
108
+ delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
109
+ end
110
+
111
+ message.postmark_attachments = [File.open("1.jpeg"), File.open("2.jpeg")]
112
+
113
+ message.deliver
114
+ # => <Mail::Message:70235449249320, Multipart: false, Headers: <From: leonard@bigbangtheory.com>, <To: sheldon@bigbangtheory.com>, <Message-ID: 91cbdb90-9daa-455d-af24-e233711b02c2>, <Subject: Have you seen these pictures of yours?>>
115
+ ```
116
+
117
+ ### Multipart message
118
+
119
+ You can send multipart messages containing both text and HTML using Postmark gem.
120
+
121
+ ``` ruby
122
+ require 'rubygems'
123
+ require 'postmark'
124
+ require 'mail'
125
+ require 'json'
126
+
127
+ message = Mail.new do
128
+ from 'sheldon@bigbangtheory.com'
129
+ to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
130
+ subject 'Re: Anything Can Happen Thursday'
131
+ delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
132
+
133
+ text_part do
134
+ body 'Apparently the news didn\'t reach my digestive system,' \
135
+ ' which when startled has it\'s own version of "Anything' \
136
+ ' Can Happen Thursday"'
137
+ end
138
+
139
+ html_part do
140
+ content_type 'text/html; charset=UTF-8'
141
+ body '<p>Apparently the news didn&rsquo;t reach my digestive ' \
142
+ 'system, which when startled has it&rsquo;s own version ' \
143
+ 'of &ldquo;Anything Can Happen Thursday&rdquo;</p>'
144
+ end
145
+ end
146
+
147
+ message.deliver
148
+ # => #<Mail::Message:70355901588620, Multipart: true, Headers: <From: sheldon@bigbangtheory.com>, <To: leonard@bigbangtheory.com>, <Message-ID: cadba131-f6d6-4cfc-9892-16ee738ba54c>, <Subject: Re: Anything Can Happen Thursday>, <Content-Type: multipart/alternative; boundary=--==_mimepart_50ef7a6234a69_a4c73ffd01035adc207b8>>
149
+ ```
150
+
151
+ ### Tagged message
152
+
153
+ Postmark also lets you tag your messages.
154
+
155
+ ``` ruby
156
+ require 'rubygems'
157
+ require 'postmark'
158
+ require 'mail'
159
+ require 'json'
160
+
161
+ message = Mail.new do
162
+ from 'sheldon@bigbangtheory.com'
163
+ to 'Penny <penny@bigbangtheory.com>'
164
+ subject 'Re: You cleaned my apartment???'
165
+ body 'I couldn\'t sleep knowing that just outside my bedroom is ' \
166
+ 'our living room and just outside our living room is that ' \
167
+ 'hallway and immediately adjacent to that hallway is this!'
168
+
169
+ delivery_method Mail::Postmark, :api_key => 'your-postmark-api-key'
170
+ end
171
+
172
+ message.tag = 'confidential'
173
+
174
+ message.deliver
175
+ # => #<Mail::Message:70168327829580, Multipart: false, Headers: <From: sheldon@bigbangtheory.com>, <To: penny@bigbangtheory.com>, <Message-ID: af2570fd-3481-4b45-8b27-a249806d891a>, <Subject: Re: You cleaned my apartment???>, <TAG: confidential>>
176
+ ```
177
+
178
+ ### Accessing Postmark Message-ID
179
+
180
+ You might want to save identifiers of messages you send. Postmark provides you
181
+ with unique Message-ID, which you can
182
+ [use to retrieve bounces](http://blog.postmarkapp.com/post/24970994681/using-messageid-to-retrieve-bounces)
183
+ later. This example shows you how to access Message-ID of a sent email message.
184
+
185
+ ``` ruby
186
+ message = Mail.new
187
+ # ...
188
+ message.deliver
189
+
190
+ message['Message-ID']
191
+ # => cadba131-f6d6-4cfc-9892-16ee738ba54c
192
+ message.message_id
193
+ # => "cadba131-f6d6-4cfc-9892-16ee738ba54c"
194
+ ```
195
+
196
+ ## Using with [TMail](http://rubygems.org/gems/tmail) library
197
+
198
+ Postmark gem also supports `tmail` library, which can be used by Ruby 1.8.7
199
+ users working on legacy projects. Please note that TMail is not supported since
200
+ 2010, so please consider using new ruby [mail](http://rubygems.org/gems/mail)
201
+ library for all your new projects.
202
+
203
+ Make sure you have a [sender signature](https://postmarkapp.com/signatures) for
204
+ every From email you specify. From can also accept array of addresses.
205
+
206
+ ``` ruby
207
+ require 'rubygems'
208
+ require 'postmark'
209
+ require 'tmail'
210
+ require 'json'
211
+
212
+ Postmark.api_key = 'your-postmark-api-key'
213
+
214
+ message = TMail::Mail.new
215
+ message.from = "leonard@bigbangtheory.com"
216
+ message.to = "Sheldon Cooper <sheldon@bigbangtheory.com>"
217
+ message.subject = "Hi Sheldon!"
218
+ message.content_type = "text/html"
219
+ message.body = "Hello my friend!"
220
+
221
+ # You can set customer headers if you like:
222
+ message["CUSTOM-HEADER"] = "my custom header value"
223
+
224
+ # Added a tag:
225
+ message.tag = "my-tracking-tag"
226
+
227
+ # Add attachments:
228
+ message.postmark_attachments = [File.open("/path"), File.open("/path")]
229
+
230
+ # Add attachments with content generated on the fly:
231
+ message.postmark_attachments = [{
232
+ "Name" => "September 2011.pdf",
233
+ "Content" => [pdf_content].pack("m"),
234
+ "ContentType" => "application/pdf"
235
+ }]
236
+
237
+ # Or specify a reply-to address (can also be an array of addresses):
238
+ message.reply_to = "penny@bigbangtheory.com"
239
+
240
+ Postmark.send_through_postmark(message)
241
+ ```
242
+
243
+ ## Exploring Other API Features
244
+
245
+ You can retrieve various information about your server state using the [Public
246
+ bounces API](http://developer.postmarkapp.com/bounces).
247
+
248
+ ``` ruby
249
+ require 'rubygems'
250
+ require 'postmark'
251
+ require 'mail'
252
+ require 'json'
253
+
254
+ Postmark.response_parser_class = :Json
255
+ Postmark.api_key = 'your-postmark-api-key'
256
+
257
+ # Delivery stats
258
+ Postmark.delivery_stats
259
+ # => {"InactiveMails"=>1, "Bounces"=>[{"Name"=>"All", "Count"=>1}, {"Type"=>"HardBounce", "Name"=>"Hard bounce", "Count"=>1}]}
260
+
261
+ # Get bounces information: (array of bounce objects)
262
+ Postmark::Bounce.all
263
+ # => [#<Postmark::Bounce:0x007ff09c04ae18 @id=580516117, @email="sheldon@bigbangtheory.com", @bounced_at=2012-10-21 00:01:56 +0800, @type="HardBounce", @name=nil, @details="smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at http://support.google.com/mail/bin/answer.py?answer=6596 c13si5382730vcw.23", @tag=nil, @dump_available=false, @inactive=true, @can_activate=true, @message_id="876d40fe-ab2a-4925-9d6f-8d5e4f4926f5", @subject="Re: What, to you, is a large crowd?">]
264
+
265
+ # Find specific bounce by id:
266
+ bounce = Postmark::Bounce.find(5)
267
+ # => #<Postmark::Bounce:0x007ff09c04ae18 @id=580516117, @email="sheldon@bigbangtheory.com", @bounced_at=2012-10-21 00:01:56 +0800, @type="HardBounce", @name=nil, @details="smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at http://support.google.com/mail/bin/answer.py?answer=6596 c13si5382730vcw.23", @tag=nil, @dump_available=false, @inactive=true, @can_activate=true, @message_id="876d40fe-ab2a-4925-9d6f-8d5e4f4926f5", @subject="Re: What, to you, is a large crowd?">
268
+
269
+ bounce.dump # string, containing raw SMTP data
270
+ # => "Return-Path: <>\r\nDate: Sun, 21 Oct 2012 01:00:04 -0400\r\nFrom: postmaster@p1.mtasv.net\r\n..."
271
+
272
+ bounce.activate # reactivate hard bounce
273
+ # => #<Postmark::Bounce:0x007ff09c04ae18 @id=580516117, @email="sheldon@bigbangtheory.com", @bounced_at=2012-10-21 00:01:56 +0800, @type="HardBounce", @name=nil, @details="smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at http://support.google.com/mail/bin/answer.py?answer=6596 c13si5382730vcw.23", @tag=nil, @dump_available=false, @inactive=true, @can_activate=true, @message_id="876d40fe-ab2a-4925-9d6f-8d5e4f4926f5", @subject="Re: What, to you, is a large crowd?">
274
+ ```
275
+
276
+ ## Security
277
+
278
+ To use SSL encryption when sending email configure the library as follows:
279
+
280
+ ``` ruby
281
+ Postmark.secure = true
282
+ ```
283
+
284
+ ## Requirements
285
+
286
+ The gem relies on Mail or TMail for building the message. You will also need
287
+ postmark account, server and sender signature set up to use it.
288
+ If you plan using it in a rails project, check out the
289
+ [postmark-rails](https://github.com/wildbit/postmark-rails/) gem, which
290
+ is meant to integrate with ActionMailer.
291
+
292
+ The plugin will try to use ActiveSupport Json if it is already included. If not,
293
+ it will attempt using the built-in ruby Json library.
294
+
295
+ You can also explicitly specify which one to be used, using
296
+
297
+ ``` ruby
298
+ Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl are also supported.
299
+ ```
300
+
301
+ ## Note on Patches/Pull Requests
302
+
303
+ * Fork the project.
304
+ * Make your feature addition or bug fix.
305
+ * Add tests for it. This is important so I don't break it in a
306
+ future version unintentionally.
307
+ * Commit, do not mess with rakefile, version, or history.
308
+ * Send me a pull request. Bonus points for topic branches.
309
+
310
+ ## Authors & Contributors
311
+
312
+ * Petyo Ivanov
313
+ * Ilya Sabanin
314
+ * Artem Chistyakov
315
+ * Hristo Deshev
316
+ * Dmitry Sabanin
317
+ * Randy Schmidt
318
+ * Chris Williams
319
+ * Aitor García Rey
320
+ * James Miller
321
+ * Yury Batenko
322
+ * Pavel Maksimenko
323
+ * Anton Astashov
324
+ * Marcus Brito
325
+ * Tyler Hunt
326
+
327
+ ## Copyright
328
+
329
+ Copyright © 2013 Wildbit LLC. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.14
1
+ 0.9.16
@@ -47,7 +47,7 @@ module Postmark
47
47
  attr_writer :response_parser_class
48
48
 
49
49
  def response_parser_class
50
- @response_parser_class ||= Object.const_defined?(:ActiveSupport) ? :ActiveSupport : :Json
50
+ @response_parser_class ||= defined?(ActiveSupport::JSON) ? :ActiveSupport : :Json
51
51
  end
52
52
 
53
53
  # The port on which your Postmark server runs.
@@ -86,16 +86,8 @@ module Postmark
86
86
  end
87
87
 
88
88
  def send_through_postmark(message) #:nodoc:
89
- @retries = 0
90
- begin
89
+ with_retries do
91
90
  HttpClient.post("email", Postmark::Json.encode(convert_message_to_options_hash(message)))
92
- rescue DeliveryError, Timeout::Error
93
- if @retries < max_retries
94
- @retries += 1
95
- retry
96
- else
97
- raise
98
- end
99
91
  end
100
92
  rescue Timeout::Error
101
93
  raise TimeoutError.new($!)
@@ -138,6 +130,17 @@ module Postmark
138
130
 
139
131
  protected
140
132
 
133
+ def with_retries
134
+ yield
135
+ rescue DeliveryError, Timeout::Error
136
+ retries = retries ? retries + 1 : 0
137
+ if retries < max_retries
138
+ retry
139
+ else
140
+ raise
141
+ end
142
+ end
143
+
141
144
  def extract_headers_according_to_message_format(message)
142
145
  if defined?(TMail) && message.is_a?(TMail::Mail)
143
146
  headers = extract_tmail_headers(message)
@@ -182,8 +185,6 @@ module Postmark
182
185
  ]
183
186
  end
184
187
 
185
-
186
-
187
188
  self.response_parser_class = nil
188
189
 
189
190
  end
@@ -3,16 +3,20 @@ require 'cgi'
3
3
  module Postmark
4
4
  module HttpClient
5
5
  extend self
6
+
7
+ @@client_mutex = Mutex.new
8
+ @@request_mutex = Mutex.new
9
+
6
10
  def post(path, data = '')
7
- handle_response(http.post(url_path(path), data, headers))
11
+ do_request { |client| client.post(url_path(path), data, headers) }
8
12
  end
9
13
 
10
14
  def put(path, data = '')
11
- handle_response(http.put(url_path(path), data, headers))
15
+ do_request { |client| client.put(url_path(path), data, headers) }
12
16
  end
13
17
 
14
18
  def get(path, query = {})
15
- handle_response(http.get(url_path(path + to_query_string(query)), headers))
19
+ do_request { |client| client.get(url_path(path + to_query_string(query)), headers) }
16
20
  end
17
21
 
18
22
  protected
@@ -53,8 +57,19 @@ module Postmark
53
57
  Postmark.path_prefix + path
54
58
  end
55
59
 
60
+ def do_request
61
+ @@request_mutex.synchronize do
62
+ handle_response(yield(http))
63
+ end
64
+ end
65
+
56
66
  def http
57
- @http ||= build_http
67
+ return @http if @http
68
+
69
+ @@client_mutex.synchronize do
70
+ return @http if @http
71
+ @http = build_http
72
+ end
58
73
  end
59
74
 
60
75
  def build_http
@@ -10,12 +10,14 @@ module Postmark
10
10
  end
11
11
 
12
12
  def postmark_attachments=(value)
13
- @_attachments = Array.wrap(value)
13
+ @_attachments = Array[*value]
14
14
  end
15
15
 
16
16
  def postmark_attachments
17
17
  return if @_attachments.nil?
18
18
 
19
+ puts @_attachments.inspect
20
+
19
21
  @_attachments.map do |item|
20
22
  if item.is_a?(Hash)
21
23
  item
@@ -1,3 +1,3 @@
1
1
  module Postmark
2
- VERSION = "0.9.15"
2
+ VERSION = "0.9.16"
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.authors = ["Petyo Ivanov", "Ilya Sabanin", "Artem Chistyakov"]
12
12
  s.date = "2012-01-31"
13
13
  s.email = "ilya@wildbit.com"
14
- s.extra_rdoc_files = ["LICENSE", "README.rdoc"]
14
+ s.extra_rdoc_files = ["LICENSE", "README.md"]
15
15
 
16
16
  s.summary = "Official Postmark API wrapper."
17
17
  s.description = "Use this gem to send emails through Postmark HTTP API and retrieve info about bounces."
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.post_install_message = %q{
25
25
  ==================
26
26
  Thanks for installing the postmark gem. If you don't have an account, please sign up at http://postmarkapp.com/.
27
- Review the README.rdoc for implementation details and examples.
27
+ Review the README.md for implementation details and examples.
28
28
  ==================
29
29
  }
30
30
 
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
 
33
33
  s.add_dependency "rake"
34
34
  s.add_dependency "json"
35
-
35
+
36
36
  s.add_development_dependency "tmail"
37
37
  s.add_development_dependency "mail"
38
38
  s.add_development_dependency "rspec-core", "~> 2.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.9.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -180,7 +180,7 @@ executables: []
180
180
  extensions: []
181
181
  extra_rdoc_files:
182
182
  - LICENSE
183
- - README.rdoc
183
+ - README.md
184
184
  files:
185
185
  - .document
186
186
  - .gitignore
@@ -189,7 +189,7 @@ files:
189
189
  - CHANGELOG.rdoc
190
190
  - Gemfile
191
191
  - LICENSE
192
- - README.rdoc
192
+ - README.md
193
193
  - Rakefile
194
194
  - VERSION
195
195
  - init.rb
@@ -215,7 +215,7 @@ homepage: http://postmarkapp.com
215
215
  licenses: []
216
216
  post_install_message: ! "\n ==================\n Thanks for installing the postmark
217
217
  gem. If you don't have an account, please sign up at http://postmarkapp.com/.\n
218
- \ Review the README.rdoc for implementation details and examples.\n ==================\n
218
+ \ Review the README.md for implementation details and examples.\n ==================\n
219
219
  \ "
220
220
  rdoc_options: []
221
221
  require_paths:
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  version: '0'
229
229
  segments:
230
230
  - 0
231
- hash: 4225198034232090078
231
+ hash: -1003524085055052038
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  none: false
234
234
  requirements:
@@ -1,126 +0,0 @@
1
- = Postmark Gem
2
-
3
- This gem is an official wrapper for Postmark HTTP API (http://postmarkapp.com). Use it to send emails and retrieve info about bounces.
4
-
5
- == Install
6
-
7
- gem install postmark
8
-
9
- In addition to the +postmark+ gem you also need to install +tmail+ or +mail+ gem. Pick the one you like most:
10
-
11
- gem install mail
12
- - or -
13
- gem install tmail
14
-
15
- == TMail Example
16
-
17
- require 'rubygems'
18
- require 'postmark'
19
- require 'tmail'
20
-
21
- Postmark.api_key = "your-api-key"
22
-
23
- # Make sure you have a sender signature for every From email you specify.
24
- # From can also accept array of addresses.
25
-
26
- message = TMail::Mail.new
27
- message.from = "leonard@bigbangtheory.com"
28
- message.to = "Sheldon Cooper <sheldon@bigbangtheory.com>"
29
- message.subject = "Hi Sheldon!"
30
- message.content_type = "text/html"
31
- message.body = "Hello my friend!"
32
-
33
- # You can set customer headers if you like:
34
- message["CUSTOM-HEADER"] = "my custom header value"
35
-
36
- # Added a tag:
37
- message.tag = "my-tracking-tag"
38
-
39
- # Add attachments:
40
- message.postmark_attachments = [File.open("/path"), File.open("/path")]
41
-
42
- # Add attachments with content generated on the fly:
43
- message.postmark_attachments = [{
44
- "Name" => "September 2011.pdf",
45
- "Content" => [pdf_content].pack("m"),
46
- "ContentType" => "application/pdf"
47
- }]
48
-
49
- # Or specify a reply-to address (can also be an array of addresses):
50
- message.reply_to = "penny@bigbangtheory.com"
51
-
52
- Postmark.send_through_postmark(message)
53
-
54
- == Mail Example
55
-
56
- require 'rubygems'
57
- require 'postmark'
58
- require 'mail'
59
-
60
- message = Mail.new
61
- message.delivery_method(Mail::Postmark, :api_key => "your-api-key")
62
- # ...
63
- # same as in example above
64
- # ...
65
- message.deliver
66
-
67
- == Other API Features
68
-
69
- You can retrieve various information about your server state using the Public bounces API - http://developer.postmarkapp.com/bounces
70
-
71
- # Get delivery stats: (JSON format)
72
- Postmark.delivery_stats
73
-
74
- # Get bounces information: (array of bounce objects)
75
- Postmark::Bounce.all
76
-
77
- # Find specific bounce by id:
78
- bounce = Postmark::Bounce.find(bounce_id)
79
- bounce.dump # string, containing raw SMTP data
80
- bounce.activate # reactivate hard bounce
81
-
82
- == Encryption
83
-
84
- To use SSL encryption when sending email configure the library as follows:
85
-
86
- Postmark.secure = true
87
-
88
- == Requirements
89
-
90
- 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.
91
- If you plan using it in a rails project, check out the postmark-rails gem, which is meant to integrate with ActionMailer.
92
-
93
- 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.
94
- You can also explicitly specify which one to be used, using
95
-
96
- Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl is also supported.
97
-
98
- == Note on Patches/Pull Requests
99
-
100
- * Fork the project.
101
- * Make your feature addition or bug fix.
102
- * Add tests for it. This is important so I don't break it in a
103
- future version unintentionally.
104
- * Commit, do not mess with rakefile, version, or history.
105
- * Send me a pull request. Bonus points for topic branches.
106
-
107
- == Authors & Contributors
108
-
109
- * Petyo Ivanov
110
- * Ilya Sabanin
111
- * Hristo Deshev
112
- * Artem Chistyakov
113
- * Dmitry Sabanin
114
- * Randy Schmidt
115
- * Chris Williams
116
- * Aitor García Rey
117
- * James Miller
118
- * Yury Batenko
119
- * Pavel Maksimenko
120
- * Anton Astashov
121
- * Marcus Brito
122
- * Tyler Hunt
123
-
124
- == Copyright
125
-
126
- Copyright (c) 2012 Wildbit LLC. See LICENSE for details.