postmark 1.8.1 → 1.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +8 -5
- data/CHANGELOG.rdoc +86 -0
- data/CONTRIBUTING.md +18 -0
- data/Gemfile +6 -5
- data/LICENSE +1 -1
- data/README.md +34 -607
- data/RELEASE.md +12 -0
- data/VERSION +1 -1
- data/gemfiles/Gemfile.legacy +5 -4
- data/lib/postmark.rb +1 -18
- data/lib/postmark/account_api_client.rb +55 -1
- data/lib/postmark/api_client.rb +145 -17
- data/lib/postmark/bounce.rb +0 -4
- data/lib/postmark/client.rb +12 -4
- data/lib/postmark/error.rb +127 -0
- data/lib/postmark/handlers/mail.rb +10 -4
- data/lib/postmark/helpers/message_helper.rb +4 -0
- data/lib/postmark/http_client.rb +20 -32
- data/lib/postmark/mail_message_converter.rb +18 -5
- data/lib/postmark/message_extensions/mail.rb +83 -8
- data/lib/postmark/version.rb +1 -1
- data/postmark.gemspec +1 -1
- data/postmark.png +0 -0
- data/spec/integration/account_api_client_spec.rb +42 -10
- data/spec/integration/api_client_hashes_spec.rb +32 -49
- data/spec/integration/api_client_messages_spec.rb +33 -52
- data/spec/integration/api_client_resources_spec.rb +12 -44
- data/spec/integration/mail_delivery_method_spec.rb +21 -23
- data/spec/spec_helper.rb +4 -7
- data/spec/support/custom_matchers.rb +44 -0
- data/spec/support/shared_examples.rb +16 -16
- data/spec/unit/postmark/account_api_client_spec.rb +239 -45
- data/spec/unit/postmark/api_client_spec.rb +792 -406
- data/spec/unit/postmark/bounce_spec.rb +40 -62
- data/spec/unit/postmark/client_spec.rb +0 -6
- data/spec/unit/postmark/error_spec.rb +231 -0
- data/spec/unit/postmark/handlers/mail_spec.rb +59 -27
- data/spec/unit/postmark/helpers/hash_helper_spec.rb +5 -6
- data/spec/unit/postmark/helpers/message_helper_spec.rb +60 -11
- data/spec/unit/postmark/http_client_spec.rb +76 -61
- data/spec/unit/postmark/inbound_spec.rb +34 -34
- data/spec/unit/postmark/inflector_spec.rb +11 -13
- data/spec/unit/postmark/json_spec.rb +2 -2
- data/spec/unit/postmark/mail_message_converter_spec.rb +250 -81
- data/spec/unit/postmark/message_extensions/mail_spec.rb +249 -38
- data/spec/unit/postmark_spec.rb +37 -37
- metadata +41 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fb0f51e437e4831ac7fe011e089ac51c00984a614f48f31e94cce6233331f3bd
|
4
|
+
data.tar.gz: 599f2b99b5a8bca7a5761c560feddac36cd252a2232431008c3eabc1ef3375b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f16405603d847f6e8b4124a7da3c478db38555196016d59cb743c4d63f154e512ffac6d9db74702340e19cfa2afdb04965fdcb3436ab92c62f031d2d2b7ba0b
|
7
|
+
data.tar.gz: 6429f12e770e5a305f2bcb705cff501c48ebeb45be85dbd78f44e32cc4b5312abd0d6d9789c5c29e7cb3fca411a4e1a748a34fdc35e703862202e7c72851a0be
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -5,24 +5,27 @@ env:
|
|
5
5
|
# POSTMARK_ACCOUNT_API_KEY=?
|
6
6
|
- secure: "lau1m+ws6T5LBiRXwd+Q0b20Wjh62W/nHnCmzOSZc2+V97XTldl3MCJdXNV7J6X7O9CzFabcAG8FSbGGwPRiyhY/qhxkYSc/9pWE8RUjyCjbw5q2RzZQelMKizyKU92eOjd6jQw/wDSZcww1OceW/pgdRjqEo21Pk6XH2yzLAd8="
|
7
7
|
# POSTMARK_CI_RECIPIENT=?
|
8
|
-
- secure: "
|
8
|
+
- secure: "XJkpUbAC1N6vcL/bUvqX2Mx8OKXpr/3zwqhjGiWhrSGKmQJUNnK4TEGFjnb1TBncZvW5cBRD0oX1Tt7gAu4o8C6sldVf35hB5FQsEyQrgSN4s95uLHuTW9EQisiQS6kzPLbkUmsMIQhIlfNGKQ5tRzRQstip81E8a0Emth3Y9EQ="
|
9
9
|
# POSTMARK_CI_SENDER=?
|
10
|
-
- secure: "
|
10
|
+
- secure: "bOoU3WEFur/SqwTY0m0aGqy8v8AZfZtFFHNYsU/BtAppZXj378CiktvJGj+cz/KMqFEWyJKNzchFOfZa45Q9Xor/QbTqkBriTOz3Ff7gQpmuPfLSvWRQSLRmbRFgr0Dk8QCTTtfnNtnajxMUyGfxwCiMo+l3EEAqjtLpN+Gja20="
|
11
11
|
language: ruby
|
12
12
|
rvm:
|
13
13
|
- 2.0.0
|
14
14
|
- 2.1.9
|
15
15
|
- 2.2.5
|
16
16
|
- 2.3.1
|
17
|
+
- 2.5.7
|
18
|
+
- 2.6.5
|
19
|
+
- 2.7.0
|
17
20
|
matrix:
|
18
21
|
include:
|
19
22
|
- rvm: 1.8.7
|
23
|
+
dist: precise
|
20
24
|
gemfile: gemfiles/Gemfile.legacy
|
21
25
|
- rvm: 1.9.3
|
22
26
|
gemfile: gemfiles/Gemfile.legacy
|
23
27
|
- rvm: jruby-19mode
|
28
|
+
jdk: oraclejdk8
|
29
|
+
dist: trusty
|
24
30
|
gemfile: gemfiles/Gemfile.legacy
|
25
31
|
script: bundle exec rake spec
|
26
|
-
before_install:
|
27
|
-
- gem update --system
|
28
|
-
- gem install bundler
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,91 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
|
+
== 1.21.3
|
4
|
+
|
5
|
+
* Remove default SSL version setting and rely on Net::HTTP/OpenSSL default.
|
6
|
+
|
7
|
+
== 1.21.2
|
8
|
+
|
9
|
+
* Ensure sending via message stream uses the correct message stream
|
10
|
+
|
11
|
+
== 1.21.1
|
12
|
+
|
13
|
+
* Fixed Postmark::ApiClient#get_message_streams
|
14
|
+
|
15
|
+
== 1.21.0
|
16
|
+
|
17
|
+
* Added support for message streams and suppressions
|
18
|
+
|
19
|
+
== 1.20.0
|
20
|
+
|
21
|
+
* Removed deprecated trigger endpoints
|
22
|
+
|
23
|
+
== 1.19.2
|
24
|
+
|
25
|
+
Allow possibility to change TLS version for HTTP client.
|
26
|
+
|
27
|
+
== 1.19.1
|
28
|
+
|
29
|
+
Bounce tags endoint removed, since it's no longer supported by API.
|
30
|
+
|
31
|
+
== 1.19.0
|
32
|
+
|
33
|
+
Webhooks management support is added.
|
34
|
+
|
35
|
+
== 1.18.0
|
36
|
+
|
37
|
+
Custom headers with any type of character casing is supported now.
|
38
|
+
|
39
|
+
== 1.17.0
|
40
|
+
|
41
|
+
* Update sent email message properly and not altering it's Message-ID with Postmark unique message id.
|
42
|
+
|
43
|
+
== 1.16.0
|
44
|
+
|
45
|
+
* Added support for template pushes.
|
46
|
+
|
47
|
+
== 1.15.0
|
48
|
+
|
49
|
+
* Extended Mail::Message objects with support for Postmark templates.
|
50
|
+
* Added ApiClient#deliver_message_with_template and ApiClient#deliver_messages_with_templates
|
51
|
+
* Removed Rake from dependencies.
|
52
|
+
|
53
|
+
== 1.14.0
|
54
|
+
|
55
|
+
* Added support for verifying DKIM/Return-Path.
|
56
|
+
* Added support for searching inbound rules.
|
57
|
+
* Updated README.
|
58
|
+
|
59
|
+
== 1.13.0
|
60
|
+
|
61
|
+
* Changed default value returned by Mail::Message#metadata to a mutable hash (makes things easier for postmark-rails).
|
62
|
+
* All message JSON payloads now include an empty metadata object even if metadata is unset.
|
63
|
+
|
64
|
+
== 1.12.0
|
65
|
+
|
66
|
+
* Added support for attaching metadata to messages.
|
67
|
+
|
68
|
+
== 1.11.0
|
69
|
+
|
70
|
+
* New, improved, and backwards-compatible gem errors (see README).
|
71
|
+
* Added support for retrieving message clicks using the Messages API.
|
72
|
+
* Added support for sending templated message in batches.
|
73
|
+
* Added support for assigning link tracking mode via `Mail::Message` headers.
|
74
|
+
|
75
|
+
== 1.10.0
|
76
|
+
|
77
|
+
* Fix a bug when open tracking flag is set to false by default, when open tracking flag is not set by a user.
|
78
|
+
* Added support for link tracking
|
79
|
+
|
80
|
+
== 1.9.1
|
81
|
+
|
82
|
+
* Fix a bug when port setting is not respected.
|
83
|
+
* Made `Postmark::HttpClient#protocol` method public.
|
84
|
+
|
85
|
+
== 1.9.0
|
86
|
+
|
87
|
+
* Added methods to access domains API endoints.
|
88
|
+
|
3
89
|
== 1.8.1
|
4
90
|
|
5
91
|
* Technical release. Fixed gemspec.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Before you report an issue or submit a pull request
|
2
|
+
|
3
|
+
*If you are blocked or need help with Postmark, please [contact
|
4
|
+
Postmark Support](https://postmarkapp.com/contact)*. For other, non-urgent
|
5
|
+
cases you’re welcome to report a bug and/or contribute to this project. We will
|
6
|
+
make our best effort to review your contributions and triage any bug reports in
|
7
|
+
a timely fashion.
|
8
|
+
|
9
|
+
If you’d like to submit a pull request:
|
10
|
+
|
11
|
+
* Fork the project.
|
12
|
+
* Make your feature addition or bug fix.
|
13
|
+
* Add tests for it. This is important to prevent future regressions.
|
14
|
+
* Do not mess with rakefile, version, or history.
|
15
|
+
* Update the CHANGELOG, list your changes under Unreleased.
|
16
|
+
* Update the README if necessary.
|
17
|
+
* Write short, descriptive commit messages, following the format used in therepo.
|
18
|
+
* Send a pull request. Bonus points for topic branches.
|
data/Gemfile
CHANGED
@@ -4,11 +4,12 @@ source "http://rubygems.org"
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem 'rspec', '~>
|
8
|
-
gem '
|
7
|
+
gem 'rspec', '~> 3.7'
|
8
|
+
gem 'rspec-its', '~> 1.2'
|
9
|
+
gem 'fakeweb', :git => 'https://github.com/chrisk/fakeweb.git'
|
9
10
|
gem 'fakeweb-matcher'
|
10
|
-
gem 'mime-types'
|
11
|
-
gem 'activesupport'
|
11
|
+
gem 'mime-types'
|
12
|
+
gem 'activesupport'
|
12
13
|
gem 'i18n', '~> 0.6.0'
|
13
14
|
gem 'yajl-ruby', '~> 1.0', :platforms => [:mingw, :mswin, :ruby]
|
14
|
-
end
|
15
|
+
end
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,638 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
This gem is the official wrapper for the [Postmark HTTP API](http://postmarkapp.com). Postmark allows you to send your application's emails with high delivery rates, including bounce/spam processing and detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.
|
5
|
-
|
6
|
-
## Install the gem
|
7
|
-
|
8
|
-
With Bundler:
|
9
|
-
|
10
|
-
``` ruby
|
11
|
-
gem 'postmark'
|
12
|
-
```
|
13
|
-
|
14
|
-
Without Bundler:
|
15
|
-
|
16
|
-
``` bash
|
17
|
-
gem install postmark
|
18
|
-
```
|
19
|
-
|
20
|
-
## Get a Postmark API token
|
21
|
-
|
22
|
-
In order to send emails using Postmark ruby gem, you will need a
|
23
|
-
[Postmark](http://postmarkapp.com) account. If you don't have one please
|
24
|
-
register at https://postmarkapp.com/sign_up.
|
25
|
-
|
26
|
-
If you didn’t create any servers yet, please create one, proceed to the
|
27
|
-
`Credentials` tab and copy an API token. API tokens should be frequently rotated for
|
28
|
-
security reasons.
|
29
|
-
|
30
|
-
## Communicating with the API
|
31
|
-
|
32
|
-
Make sure you have a [sender signature](https://postmarkapp.com/signatures) for
|
33
|
-
every From email address you specify.
|
34
|
-
|
35
|
-
Create an instance of `Postmark::ApiClient` to start sending emails.
|
36
|
-
|
37
|
-
``` ruby
|
38
|
-
your_api_token = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
39
|
-
client = Postmark::ApiClient.new(your_api_token)
|
40
|
-
```
|
41
|
-
|
42
|
-
`Postmark::ApiClient` accepts various options:
|
43
|
-
|
44
|
-
``` ruby
|
45
|
-
client = Postmark::ApiClient.new(your_api_token, http_open_timeout: 15)
|
46
|
-
```
|
47
|
-
|
48
|
-
Some useful options are:
|
49
|
-
|
50
|
-
* `secure` (`true` or `false`): set to false to disable SSL connection.
|
51
|
-
* `http_read_timeout` (positive number): limit HTTP read time to `n` seconds.
|
52
|
-
* `http_open_timeout` (positive number): limit HTTP open time to `n` seconds.
|
53
|
-
* `proxy_host` (string): proxy address to use.
|
54
|
-
* `proxy_port` (positive number): proxy port to use.
|
55
|
-
* `proxy_user` (string): proxy user.
|
56
|
-
* `proxy_pass` (string): proxy password.
|
57
|
-
|
58
|
-
## Sending a plain text message
|
59
|
-
|
60
|
-
``` ruby
|
61
|
-
client.deliver(from: 'sheldon@bigbangtheory.com',
|
62
|
-
to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
|
63
|
-
subject: 'Re: Come on, Sheldon. It will be fun.',
|
64
|
-
text_body: 'That\'s what you said about the Green Lantern ' \
|
65
|
-
'movie. You were 114 minutes of wrong.')
|
66
|
-
# => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:45:16.2059023-04:00", :message_id=>"b2b268e3-6a70-xxxx-b897-49c9eb8b1d2e", :error_code=>0, :message=>"OK"}
|
67
|
-
```
|
68
|
-
|
69
|
-
## Sending an HTML message (with open tracking!)
|
70
|
-
|
71
|
-
Simply pass an HTML document as html_body parameter to `#deliver`. You can also enable open tracking by setting `track_opens` to `true`.
|
72
|
-
|
73
|
-
``` ruby
|
74
|
-
client.deliver(from: 'sheldon@bigbangtheory.com',
|
75
|
-
to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
|
76
|
-
subject: 'Re: What, to you, is a large crowd?',
|
77
|
-
html_body: '<p>Any group big enough to trample me to death. ' \
|
78
|
-
'General rule of thumb is 36 adults or 70 ' \
|
79
|
-
'children.</p>',
|
80
|
-
track_opens: true)
|
81
|
-
# => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:51:08.8789433-04:00", :message_id=>"75c28987-564e-xxxx-b6eb-e8071873ac06", :error_code=>0, :message=>"OK"}
|
82
|
-
```
|
83
|
-
|
84
|
-
## Sending a message with attachments
|
85
|
-
|
86
|
-
You can add
|
87
|
-
[attachments](http://developer.postmarkapp.com/developer-build.html#attachments)
|
88
|
-
to your messages. Keep in mind message size limit (contents and attachment) is currently 10 MB. For inline attachments it is possible to specify content IDs via the `content_id` attribute.
|
89
|
-
|
90
|
-
``` ruby
|
91
|
-
client.deliver(from: 'leonard@bigbangtheory.com',
|
92
|
-
to: 'Dr. Sheldon Cooper <sheldon@bigbangtheory.com>',
|
93
|
-
subject: 'Have you seen these pictures of yours?',
|
94
|
-
text_body: 'You look like a real geek!',
|
95
|
-
html_body: '<p>You look like a real geek!</p><center><img src="cid:42"></center>',
|
96
|
-
attachments: [File.open('1.jpeg'),
|
97
|
-
{name: 'sheldon.jpeg',
|
98
|
-
content: [File.read('2.jpeg')].pack('m'),
|
99
|
-
content_type: 'image/jpeg'},
|
100
|
-
{name: 'logo.png',
|
101
|
-
content: [File.read('1.png')].pack('m'),
|
102
|
-
content_type: 'image/png',
|
103
|
-
content_id: 'cid:42'}])
|
104
|
-
|
105
|
-
# => {:to=>"Dr. Sheldon Cooper <sheldon@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:56:12.2828813-04:00", :message_id=>"8ec0d283-8b93-xxxx-9d65-241d1777cf0f", :error_code=>0, :message=>"OK"}
|
106
|
-
```
|
107
|
-
|
108
|
-
## Sending a multipart message
|
109
|
-
|
110
|
-
``` ruby
|
111
|
-
client.deliver(from: 'sheldon@bigbangtheory.com',
|
112
|
-
to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
|
113
|
-
subject: 'Re: Anything Can Happen Thursday',
|
114
|
-
text_body: 'Apparently the news didn\'t reach my digestive ' \
|
115
|
-
'system, which when startled has it\'s own version ' \
|
116
|
-
'of "Anything Can Happen Thursday"',
|
117
|
-
html_body: '<p>Apparently the news didn’t reach my ' \
|
118
|
-
'digestive system, which when startled has ' \
|
119
|
-
'it’s own version of “Anything Can '\
|
120
|
-
'Happen Thursday”</p>')
|
121
|
-
# => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T02:58:00.089828-04:00", :message_id=>"bc973458-1315-xxxx-b295-6aa0a2b631ac", :error_code=>0, :message=>"OK"}
|
122
|
-
```
|
123
|
-
|
124
|
-
## Tagging messages
|
125
|
-
|
126
|
-
You can categorize outgoing email using the optional `:tag` property. If you use
|
127
|
-
different tags for the different types of emails your application generates,
|
128
|
-
you will be able to get detailed statistics for them through the Postmark user
|
129
|
-
interface.
|
130
|
-
|
131
|
-
``` ruby
|
132
|
-
client.deliver(from: 'sheldon@bigbangtheory.com',
|
133
|
-
to: 'Penny <penny@bigbangtheory.com>',
|
134
|
-
subject: 'Re: You cleaned my apartment???',
|
135
|
-
text_body: 'I couldn\'t sleep knowing that just outside my ' \
|
136
|
-
'bedroom is our living room and just outside our ' \
|
137
|
-
'living room is that hallway and immediately adjacent ' \
|
138
|
-
'to that hallway is this!',
|
139
|
-
tag: 'confidential')
|
140
|
-
|
141
|
-
# => {:to=>"Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T03:00:55.4454938-04:00", :message_id=>"34aed4b3-3a95-xxxx-bd1d-88064909cc93", :error_code=>0, :message=>"OK"}
|
142
|
-
```
|
143
|
-
|
144
|
-
## Sending to multiple recipients
|
145
|
-
|
146
|
-
You can pass multiple recipient addresses in the `:to` field and the optional
|
147
|
-
`:cc` and `:bcc` fields. Note that Postmark has a limit of 50 recipients
|
148
|
-
per message in total. You need to take care not to exceed that limit.
|
149
|
-
Otherwise, you will get an error.
|
1
|
+
<a href="https://postmarkapp.com">
|
2
|
+
<img src="postmark.png" alt="Postmark Logo" title="Postmark" width="120" height="120" align="right">
|
3
|
+
</a>
|
150
4
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
cc: ['Dr. Koothrappali <raj@bigbangtheory.com>'],
|
156
|
-
bcc: 'secretsheldonstorage@bigbangtheory.com',
|
157
|
-
subject: 'Re: Come on, Sheldon. It will be fun.',
|
158
|
-
text_body: 'That\'s what you said about the Green Lantern ' \
|
159
|
-
'movie. You were 114 minutes of wrong.')
|
160
|
-
# => {:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>, Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T05:04:16.3247488-04:00", :message_id=>"d647c5d6-xxxx-466d-9411-557dcd5c2297", :error_code=>0, :message=>"OK"}
|
161
|
-
```
|
162
|
-
|
163
|
-
## Sending a templated email
|
164
|
-
|
165
|
-
If you have a [template created](https://github.com/wildbit/postmark-gem/wiki/The-Templates-API-support) in Postmark you can send an email using that template.
|
166
|
-
|
167
|
-
``` ruby
|
168
|
-
client.deliver_with_template(from: 'sheldon@bigbangtheory.com',
|
169
|
-
to: 'Penny <penny@bigbangtheory.com>',
|
170
|
-
template_id: 123,
|
171
|
-
template_model: {
|
172
|
-
name: 'Penny',
|
173
|
-
message: 'Bazinga!'
|
174
|
-
})
|
175
|
-
|
176
|
-
# => {:to=>"Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T03:00:55.4454938-04:00", :message_id=>"34aed4b3-3a95-xxxx-bd1d-88064909cc93", :error_code=>0, :message=>"OK"}
|
177
|
-
```
|
178
|
-
|
179
|
-
## Sending in batches
|
180
|
-
|
181
|
-
While Postmark is focused on transactional email, we understand that developers
|
182
|
-
with higher volumes or processing time constraints need to send their messages
|
183
|
-
in batches. To facilitate this we provide a batching endpoint that permits you
|
184
|
-
to send up to 500 well-formed Postmark messages in a single API call.
|
185
|
-
|
186
|
-
``` ruby
|
187
|
-
messages = []
|
188
|
-
|
189
|
-
messages << {from: 'sheldon@bigbangtheory.com',
|
190
|
-
to: 'Leonard Hofstadter <leonard@bigbangtheory.com>',
|
191
|
-
subject: 'Re: Come on, Sheldon. It will be fun.',
|
192
|
-
text_body: 'That\'s what you said about the Green Lantern ' \
|
193
|
-
'movie. You were 114 minutes of wrong.'}
|
194
|
-
|
195
|
-
messages << {from: 'sheldon@bigbangtheory.com',
|
196
|
-
to: 'Penny <penny@bigbangtheory.com>',
|
197
|
-
subject: 'Re: You cleaned my apartment???',
|
198
|
-
text_body: 'I couldn\'t sleep knowing that just outside my ' \
|
199
|
-
'bedroom is our living room and just outside our ' \
|
200
|
-
'living room is that hallway and immediately ' \
|
201
|
-
'adjacent to that hallway is this!',
|
202
|
-
tag: 'confidential'}
|
203
|
-
|
204
|
-
client.deliver_in_batches(messages)
|
205
|
-
# => [{:to=>"Leonard Hofstadter <leonard@bigbangtheory.com>", :submitted_at=>"2013-05-09T05:19:16.3361118-04:00", :message_id=>"247e43a9-6b0d-4914-a87f-7b74bf76b5cb", :error_code=>0, :message=>"OK"}, {:to=>"Penny <penny@bigbangtheory.com>", :submitted_at=>"2013-05-09T05:19:16.3517099-04:00", :message_id=>"26467642-f169-4da8-87a8-b89154067dfb", :error_code=>0, :message=>"OK"}]
|
206
|
-
```
|
207
|
-
|
208
|
-
## Parsing inbound
|
209
|
-
|
210
|
-
Inbound processing allows you (or your users) to send emails to Postmark, which we then
|
211
|
-
process and deliver to you via a web hook in a nicely formatted JSON document.
|
212
|
-
|
213
|
-
Here is a simple Ruby/Sinatra application that does basic inbound processing.
|
214
|
-
|
215
|
-
``` ruby
|
216
|
-
logger = Logger.new(STDOUT)
|
217
|
-
|
218
|
-
class Comment
|
219
|
-
attr_accessor :attributes
|
220
|
-
|
221
|
-
def self.create_from_inbound_hook(message)
|
222
|
-
self.new(:text => message["TextBody"],
|
223
|
-
:user_email => message["From"],
|
224
|
-
:discussion_id => message["MailboxHash"])
|
225
|
-
end
|
226
|
-
|
227
|
-
def initialize(attributes={})
|
228
|
-
@attributes = attributes
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
post '/inbound' do
|
233
|
-
request.body.rewind
|
234
|
-
comment = Comment.create_from_inbound_hook(Postmark::Json.decode(request.body.read))
|
235
|
-
logger.info comment.inspect
|
236
|
-
end
|
237
|
-
```
|
238
|
-
|
239
|
-
If you don’t like that the fields of the Inbound JSON document are all in CamelCase, you
|
240
|
-
can use the `Postmark::Inbound.to_ruby_hash` method to give it some Ruby flavor.
|
241
|
-
|
242
|
-
```
|
243
|
-
postmark_hash = Postmark::Json.decode(request.body.read)
|
244
|
-
ruby_hash = Postmark::Inbound.to_ruby_hash(postmark_hash)
|
245
|
-
# => {:from=>"myUser@theirDomain.com", :from_full=>{:email=>"myUser@theirDomain.com", :name=>"John Doe"}, :to=>"451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com", :to_full=>[{:email=>"451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com", :name=>""}], :cc=>"\"Full name\" <sample.cc@emailDomain.com>, \"Another Cc\" <another.cc@emailDomain.com>", :cc_full=>[{:email=>"sample.cc@emailDomain.com", :name=>"Full name"}, {:email=>"another.cc@emailDomain.com", :name=>"Another Cc"}], :reply_to=>"myUsersReplyAddress@theirDomain.com", :subject=>"This is an inbound message", :message_id=>"22c74902-a0c1-4511-804f2-341342852c90", :date=>"Thu, 5 Apr 2012 16:59:01 +0200", :mailbox_hash=>"ahoy", :text_body=>"[ASCII]", :html_body=>"[HTML(encoded)]", :tag=>"", :headers=>[{:name=>"X-Spam-Checker-Version", :value=>"SpamAssassin 3.3.1 (2010-03-16) onrs-ord-pm-inbound1.wildbit.com"}, {:name=>"X-Spam-Status", :value=>"No"}, {:name=>"X-Spam-Score", :value=>"-0.1"}, {:name=>"X-Spam-Tests", :value=>"DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"}, {:name=>"Received-SPF", :value=>"Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.160.180; helo=mail-gy0-f180.google.com; envelope-from=myUser@theirDomain.com; receiver=451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com"}, {:name=>"DKIM-Signature", :value=>"v=1; a=rsa-sha256; c=relaxed/relaxed; d=wildbit.com; s=google; h=mime-version:reply-to:date:message-id:subject:from:to:cc :content-type; bh=cYr/+oQiklaYbBJOQU3CdAnyhCTuvemrU36WT7cPNt0=; b=QsegXXbTbC4CMirl7A3VjDHyXbEsbCUTPL5vEHa7hNkkUTxXOK+dQA0JwgBHq5C+1u iuAJMz+SNBoTqEDqte2ckDvG2SeFR+Edip10p80TFGLp5RucaYvkwJTyuwsA7xd78NKT Q9ou6L1hgy/MbKChnp2kxHOtYNOrrszY3JfQM="}, {:name=>"MIME-Version", :value=>"1.0"}, {:name=>"Message-ID", :value=>"<CAGXpo2WKfxHWZ5UFYCR3H_J9SNMG+5AXUovfEFL6DjWBJSyZaA@mail.gmail.com>"}], :attachments=>[{:name=>"myimage.png", :content=>"[BASE64-ENCODED CONTENT]", :content_type=>"image/png", :content_length=>4096}, {:name=>"mypaper.doc", :content=>"[BASE64-ENCODED CONTENT]", :content_type=>"application/msword", :content_length=>16384}]}
|
246
|
-
```
|
247
|
-
|
248
|
-
## Working with bounces
|
249
|
-
|
250
|
-
Use `#get_bounces` to retrieve a list of bounces (use `:count` and `:offset`
|
251
|
-
parameters to control pagination).
|
252
|
-
|
253
|
-
``` ruby
|
254
|
-
client.get_bounces(count: 1, offset: 0)
|
255
|
-
# => [{:id=>654714902, :type=>"Transient", :type_code=>2, :name=>"Message delayed", :message_id=>"1fdf3729-xxxx-4d5c-8a7b-96da7a23268b", :description=>"The server could not temporarily deliver your message (ex: Message is delayed due to network troubles).", :details=>"action: failed\r\n", :email=>"tema@wildbit.org", :bounced_at=>"2013-04-10T01:01:35.0965184-04:00", :dump_available=>true, :inactive=>false, :can_activate=>true, :subject=>"bounce test"}]
|
256
|
-
```
|
257
|
-
|
258
|
-
Use `#get_bounced_tags` to retrieve a list of tags used for bounced emails.
|
259
|
-
|
260
|
-
``` ruby
|
261
|
-
client.get_bounced_tags
|
262
|
-
# => ["confidential"]
|
263
|
-
```
|
264
|
-
|
265
|
-
Use `#get_bounce` to get info for a specific bounce using ID:
|
266
|
-
|
267
|
-
``` ruby
|
268
|
-
client.get_bounce(654714902)
|
269
|
-
# => {:id=>654714902, :type=>"Transient", :type_code=>2, :name=>"Message delayed", :message_id=>"1fdf3729-xxxx-xxxx-8a7b-96da7a23268b", :description=>"The server could not temporarily deliver your message (ex: Message is delayed due to network troubles).", :details=>"action: failed\r\n", :email=>"tema@wildbit.com", :bounced_at=>"2013-04-10T01:01:35.0965184-04:00", :dump_available=>true, :inactive=>false, :can_activate=>true, :subject=>"bounce test", :content=>"..."}
|
270
|
-
```
|
5
|
+
# Postmark Ruby Gem
|
6
|
+
[](https://travis-ci.org/wildbit/postmark-gem) [](https://codeclimate.com/github/wildbit/postmark-gem)
|
7
|
+
[](http://www.opensource.org/licenses/MIT)
|
8
|
+
[](https://badge.fury.io/rb/postmark)
|
271
9
|
|
272
|
-
|
10
|
+
Postmark allows you to send your emails with high delivery rates. It also includes detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.
|
273
11
|
|
274
|
-
|
275
|
-
client.dump_bounce(654714902)
|
276
|
-
# => {:body=>"Return-Path: <>\r\nReceived: from m1.mtasv.net (74.205.19.136) by sc-ord-mail2.mtasv.net id hcjov61jk5ko for <pm_bounces@pm.mtasv.net>; Wed, 10 Apr 2013 01:00:35 -0400 (envelope-from <>)\r\nDate: Wed, 10 Apr 2013 01:00:48 -0400\r\nFrom: postmaster@m1.mtasv.net\r\n..."}
|
277
|
-
```
|
12
|
+
This gem is the official wrapper for the [Postmark HTTP API](http://postmarkapp.com).
|
278
13
|
|
279
|
-
|
14
|
+
## Usage
|
280
15
|
|
281
|
-
|
282
|
-
|
283
|
-
# => [{...}, {...}]
|
284
|
-
```
|
16
|
+
Please see the [wiki](https://github.com/wildbit/postmark-gem/wiki) for detailed instructions about sending email, using the bounce api and other Postmark API features.
|
17
|
+
For details about Postmark API in general, please check out [Postmark developer docs](https://postmarkapp.com/developer).
|
285
18
|
|
286
|
-
|
19
|
+
## Requirements
|
287
20
|
|
288
|
-
|
289
|
-
client.activate_bounce(654714902)
|
290
|
-
# => {:id=>654714902, :type=>"Transient", :type_code=>2, :name=>"Message delayed", :message_id=>"1fdf3729-xxxx-xxxx-xxxx-96da7a23268b", :description=>"The server could not temporarily deliver your message (ex: Message is delayed due to network troubles).", :details=>"action: failed\r\n", :email=>"tema@wildbit.com", :bounced_at=>"2013-04-10T01:01:35.0965184-04:00", :dump_available=>true, :inactive=>false, :can_activate=>true, :subject=>"bounce test"}
|
291
|
-
```
|
21
|
+
You will need a Postmark account, server and sender signature (or verified domain) set up to use it. For details about setup, check out [wiki pages](https://github.com/wildbit/postmark-gem/wiki/Getting-Started).
|
292
22
|
|
293
|
-
|
23
|
+
If you plan using the library in a Rails project, check out the [postmark-rails](https://github.com/wildbit/postmark-rails/) gem, which
|
24
|
+
is meant to integrate with ActionMailer. The plugin will try to use ActiveSupport JSon if it is already included. If not,
|
25
|
+
it will attempt to use the built-in Ruby JSon library.
|
294
26
|
|
295
|
-
|
296
|
-
by type.
|
27
|
+
You can also explicitly specify which one to be used, using following code:
|
297
28
|
|
298
29
|
``` ruby
|
299
|
-
|
300
|
-
# => {:inactive_mails=>1, :bounces=>[{:name=>"All", :count=>3}, {:type=>"HardBounce", :name=>"Hard bounce", :count=>2}, {:type=>"Transient", :name=>"Message delayed", :count=>1}]}
|
30
|
+
Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl are also supported.
|
301
31
|
```
|
302
32
|
|
303
|
-
##
|
33
|
+
## Installation
|
304
34
|
|
305
|
-
|
35
|
+
You can use the library with or without a Bundler.
|
306
36
|
|
307
|
-
|
308
|
-
client.server_info
|
309
|
-
# => {:name=>"Testing", :color=>"blue", :bounce_hook_url=>"", :inbound_hash=>"c2ffffff74f8643e5f6086c81", :inbound_hook_url=>"", :smtp_api_activated=>true}
|
310
|
-
```
|
311
|
-
|
312
|
-
For example, you can use `#update_server_info` to set inbound hook URL:
|
37
|
+
With Bundler:
|
313
38
|
|
314
39
|
``` ruby
|
315
|
-
|
40
|
+
gem 'postmark'
|
316
41
|
```
|
317
42
|
|
318
|
-
|
319
|
-
|
320
|
-
You can use Postmark with the `mail` gem.
|
43
|
+
Without Bundler:
|
321
44
|
|
322
45
|
``` bash
|
323
|
-
gem install
|
324
|
-
```
|
325
|
-
|
326
|
-
Make sure you have a [sender signature](https://postmarkapp.com/signatures) for
|
327
|
-
every `From` email address you specify.
|
328
|
-
|
329
|
-
To send a `Mail::Message` via Postmark you’ll need to specify `Mail::Postmark` as
|
330
|
-
a delivery method for the message:
|
331
|
-
|
332
|
-
``` ruby
|
333
|
-
message = Mail.new do
|
334
|
-
# ...
|
335
|
-
delivery_method Mail::Postmark, api_token: 'your-postmark-api-token'
|
336
|
-
end
|
337
|
-
```
|
338
|
-
|
339
|
-
Delivery method accepts all options supported by `Postmark::ApiClient`
|
340
|
-
documented above. A new instance of `Postmark::ApiClient` is created every time
|
341
|
-
you deliver a message to preserve thread safety.
|
342
|
-
|
343
|
-
If you would prefer to use Postmark as the default delivery method for all
|
344
|
-
`Mail::Message` instances, you can call `Mail.defaults` method during the initialization
|
345
|
-
step of your app:
|
346
|
-
|
347
|
-
``` ruby
|
348
|
-
Mail.defaults do
|
349
|
-
delivery_method Mail::Postmark, api_token: 'your-postmark-api-token'
|
350
|
-
end
|
351
|
-
```
|
352
|
-
|
353
|
-
## Plain text message
|
354
|
-
|
355
|
-
``` ruby
|
356
|
-
require 'rubygems'
|
357
|
-
require 'postmark'
|
358
|
-
require 'mail'
|
359
|
-
require 'json'
|
360
|
-
|
361
|
-
message = Mail.new do
|
362
|
-
from 'sheldon@bigbangtheory.com'
|
363
|
-
to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
|
364
|
-
subject 'Re: Come on, Sheldon. It will be fun.'
|
365
|
-
body 'That\'s what you said about the Green Lantern movie. You' \
|
366
|
-
'were 114 minutes of wrong.'
|
367
|
-
|
368
|
-
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
|
369
|
-
end
|
370
|
-
|
371
|
-
message.deliver
|
372
|
-
# => #<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.>>
|
373
|
-
```
|
374
|
-
|
375
|
-
## HTML message (with open tracking)
|
376
|
-
|
377
|
-
Notice that we set `track_opens` field to `true`, to enable open tracking for this message.
|
378
|
-
|
379
|
-
``` ruby
|
380
|
-
require 'rubygems'
|
381
|
-
require 'postmark'
|
382
|
-
require 'mail'
|
383
|
-
require 'json'
|
384
|
-
|
385
|
-
message = Mail.new do
|
386
|
-
from 'sheldon@bigbangtheory.com'
|
387
|
-
to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
|
388
|
-
subject 'Re: What, to you, is a large crowd?'
|
389
|
-
|
390
|
-
content_type 'text/html; charset=UTF-8'
|
391
|
-
body '<p>Any group big enough to trample me to death. General ' \
|
392
|
-
'rule of thumb is 36 adults or 70 children.</p>'
|
393
|
-
|
394
|
-
track_opens "true" # Feel free to use boolean values on mail >= 2.3.0
|
395
|
-
|
396
|
-
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
|
397
|
-
end
|
398
|
-
|
399
|
-
message.deliver
|
400
|
-
# => #<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>>
|
401
|
-
```
|
402
|
-
|
403
|
-
## Message with attachments
|
404
|
-
|
405
|
-
``` ruby
|
406
|
-
message = Mail.new do
|
407
|
-
from 'leonard@bigbangtheory.com'
|
408
|
-
to 'Dr. Sheldon Cooper <sheldon@bigbangtheory.com>'
|
409
|
-
subject 'Have you seen these pictures of yours?'
|
410
|
-
body 'You look like a real geek!'
|
411
|
-
add_file '1.jpeg'
|
412
|
-
|
413
|
-
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
|
414
|
-
end
|
415
|
-
|
416
|
-
message.attachments['sheldon.jpeg'] = File.read('2.jpeg')
|
417
|
-
|
418
|
-
message.deliver
|
419
|
-
# => #<Mail::Message:70185826686240, Multipart: true, Headers: <From: leonard@bigbangtheory.com>, <To: sheldon@bigbangtheory.com>, <Message-ID: ba644cc1-b5b1-4bcb-aaf8-2f290b5aad80>, <Subject: Have you seen these pictures of yours?>, <Content-Type: multipart/mixed; boundary=--==_mimepart_5121f9f1ec653_12c53fd569035ad817726>>
|
420
|
-
```
|
421
|
-
|
422
|
-
You can also make an attachment inline:
|
423
|
-
|
424
|
-
``` ruby
|
425
|
-
message.attachments.inline['sheldon.jpeg'] = File.read('2.jpeg')
|
426
|
-
```
|
427
|
-
|
428
|
-
Then simply use `Mail::Part#url` method to reference it from your email body.
|
429
|
-
|
430
|
-
``` erb
|
431
|
-
<p><img src="<%= message.attachments['sheldon.jpeg'].url %>" alt="Dr. Sheldon Cooper"></p>
|
432
|
-
```
|
433
|
-
|
434
|
-
## Multipart message
|
435
|
-
|
436
|
-
You can send multipart messages containing both text and HTML using the Postmark gem.
|
437
|
-
|
438
|
-
``` ruby
|
439
|
-
require 'rubygems'
|
440
|
-
require 'postmark'
|
441
|
-
require 'mail'
|
442
|
-
require 'json'
|
443
|
-
|
444
|
-
message = Mail.new do
|
445
|
-
from 'sheldon@bigbangtheory.com'
|
446
|
-
to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
|
447
|
-
subject 'Re: Anything Can Happen Thursday'
|
448
|
-
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
|
449
|
-
|
450
|
-
text_part do
|
451
|
-
body 'Apparently the news didn\'t reach my digestive system,' \
|
452
|
-
' which when startled has it\'s own version of "Anything' \
|
453
|
-
' Can Happen Thursday"'
|
454
|
-
end
|
455
|
-
|
456
|
-
html_part do
|
457
|
-
content_type 'text/html; charset=UTF-8'
|
458
|
-
body '<p>Apparently the news didn’t reach my digestive ' \
|
459
|
-
'system, which when startled has it’s own version ' \
|
460
|
-
'of “Anything Can Happen Thursday”</p>'
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
message.deliver
|
465
|
-
# => #<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>>
|
466
|
-
```
|
467
|
-
|
468
|
-
## Tagged message
|
469
|
-
|
470
|
-
Postmark also lets you tag your messages.
|
471
|
-
|
472
|
-
``` ruby
|
473
|
-
require 'rubygems'
|
474
|
-
require 'postmark'
|
475
|
-
require 'mail'
|
476
|
-
require 'json'
|
477
|
-
|
478
|
-
message = Mail.new do
|
479
|
-
from 'sheldon@bigbangtheory.com'
|
480
|
-
to 'Penny <penny@bigbangtheory.com>'
|
481
|
-
subject 'Re: You cleaned my apartment???'
|
482
|
-
body 'I couldn\'t sleep knowing that just outside my bedroom is ' \
|
483
|
-
'our living room and just outside our living room is that ' \
|
484
|
-
'hallway and immediately adjacent to that hallway is this!'
|
485
|
-
tag 'confidential'
|
486
|
-
|
487
|
-
delivery_method Mail::Postmark, :api_token => 'your-postmark-api-token'
|
488
|
-
end
|
489
|
-
|
490
|
-
message.deliver
|
491
|
-
# => #<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>>
|
492
|
-
```
|
493
|
-
|
494
|
-
## Sending in batches
|
495
|
-
|
496
|
-
You can also send `Mail::Message` objects in batches. Create an instance of
|
497
|
-
`Postmark::ApiClient` as described in "Communicating with the API" section.
|
498
|
-
|
499
|
-
``` ruby
|
500
|
-
messages = []
|
501
|
-
|
502
|
-
messages << Mail.new do
|
503
|
-
from 'sheldon@bigbangtheory.com'
|
504
|
-
to 'Leonard Hofstadter <leonard@bigbangtheory.com>'
|
505
|
-
subject 'Re: Come on, Sheldon. It will be fun.'
|
506
|
-
body 'That\'s what you said about the Green Lantern movie. You' \
|
507
|
-
'were 114 minutes of wrong.'
|
508
|
-
end
|
509
|
-
|
510
|
-
messages << Mail.new do
|
511
|
-
from 'sheldon@bigbangtheory.com'
|
512
|
-
to 'Penny <penny@bigbangtheory.com>'
|
513
|
-
subject 'Re: You cleaned my apartment???'
|
514
|
-
body 'I couldn\'t sleep knowing that just outside my bedroom is ' \
|
515
|
-
'our living room and just outside our living room is that ' \
|
516
|
-
'hallway and immediately adjacent to that hallway is this!'
|
517
|
-
tag 'confidential'
|
518
|
-
end
|
519
|
-
|
520
|
-
client.deliver_messages(messages)
|
521
|
-
# => [{:to=>"leonard@bigbangtheory.com", :submitted_at=>"2013-05-10T01:59:29.830486-04:00", :message_id=>"8ad0e8b0-xxxx-xxxx-951d-223c581bb467", :error_code=>0, :message=>"OK"}, {:to=>"penny@bigbangtheory.com", :submitted_at=>"2013-05-10T01:59:29.830486-04:00", :message_id=>"33c6240c-xxxx-xxxx-b0df-40bdfcf4e0f7", :error_code=>0, :message=>"OK"}]
|
522
|
-
```
|
523
|
-
|
524
|
-
After delivering a batch you can check on each message’s delivery status:
|
525
|
-
|
526
|
-
``` ruby
|
527
|
-
messages.first.delivered?
|
528
|
-
# => true
|
529
|
-
|
530
|
-
messages.all?(&:delivered)
|
531
|
-
# => true
|
532
|
-
```
|
533
|
-
|
534
|
-
Or even get a related Postmark response:
|
535
|
-
|
536
|
-
``` ruby
|
537
|
-
messages.first.postmark_response
|
538
|
-
# => {"To"=>"leonard@bigbangtheory.com", "SubmittedAt"=>"2013-05-10T01:59:29.830486-04:00", "MessageID"=>"8ad0e8b0-xxxx-xxxx-951d-223c581bb467", "ErrorCode"=>0, "Message"=>"OK"}
|
539
|
-
```
|
540
|
-
|
541
|
-
## Accessing Postmark Message-ID
|
542
|
-
|
543
|
-
You might want to save identifiers of messages you send. Postmark provides you
|
544
|
-
with a unique Message-ID, which you can
|
545
|
-
[use to retrieve bounces](http://blog.postmarkapp.com/post/24970994681/using-messageid-to-retrieve-bounces)
|
546
|
-
later. This example shows you how to access the Message-ID of a sent email message.
|
547
|
-
|
548
|
-
``` ruby
|
549
|
-
message = Mail.new
|
550
|
-
# ...
|
551
|
-
message.deliver
|
552
|
-
|
553
|
-
message['Message-ID']
|
554
|
-
# => cadba131-f6d6-4cfc-9892-16ee738ba54c
|
555
|
-
message.message_id
|
556
|
-
# => "cadba131-f6d6-4cfc-9892-16ee738ba54c"
|
557
|
-
```
|
558
|
-
|
559
|
-
# Exploring Other Gem Features
|
560
|
-
|
561
|
-
## The Account API Support
|
562
|
-
|
563
|
-
Postmark allows you to automatically scale your sending infrastructure with the Account API. Learn how in the [Account API Support](https://github.com/wildbit/postmark-gem/wiki/The-Account-API-Support) guide.
|
564
|
-
|
565
|
-
## The Triggers API Support
|
566
|
-
|
567
|
-
[The Triggers API](https://github.com/wildbit/postmark-gem/wiki/The-Triggers-API-Support) can be used to tell Postmark to automatically track opens for all messages with a certain tag.
|
568
|
-
|
569
|
-
## The Messages API Support
|
570
|
-
|
571
|
-
If you ever need to access your messages or their metadata (i.e. open tracking info), [the Messages API](https://github.com/wildbit/postmark-gem/wiki/The-Messages-API-support) is a great place to start.
|
572
|
-
|
573
|
-
## The Templates API Support
|
574
|
-
|
575
|
-
[The Templates API](https://github.com/wildbit/postmark-gem/wiki/The-Templates-API-support) can be used to fully manage your templates.
|
576
|
-
|
577
|
-
## The Stats API Support
|
578
|
-
|
579
|
-
[The Stats API](https://github.com/wildbit/postmark-gem/wiki/The-Stats-API-support) can be used to access statistics on your emails sent by date and tag.
|
580
|
-
|
581
|
-
|
582
|
-
## ActiveModel-like Interface For Bounces
|
583
|
-
|
584
|
-
To provide an interface similar to ActiveModel for bounces, the Postmark gem adds
|
585
|
-
`Postmark::Bounce` class. This class uses the shared `Postmark::ApiClient` instance
|
586
|
-
configured through the Postmark module.
|
587
|
-
|
588
|
-
``` ruby
|
589
|
-
require 'rubygems'
|
590
|
-
require 'postmark'
|
591
|
-
require 'mail'
|
592
|
-
require 'json'
|
593
|
-
|
594
|
-
Postmark.response_parser_class = :Json
|
595
|
-
Postmark.api_token = 'your-postmark-api-token'
|
596
|
-
|
597
|
-
# Get bounces information: (array of bounce objects)
|
598
|
-
Postmark::Bounce.all
|
599
|
-
# => [#<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?">]
|
600
|
-
|
601
|
-
# Find specific bounce by id:
|
602
|
-
bounce = Postmark::Bounce.find(5)
|
603
|
-
# => #<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?">
|
604
|
-
|
605
|
-
bounce.dump # string, containing raw SMTP data
|
606
|
-
# => "Return-Path: <>\r\nDate: Sun, 21 Oct 2012 01:00:04 -0400\r\nFrom: postmaster@p1.mtasv.net\r\n..."
|
607
|
-
|
608
|
-
bounce.activate # reactivate hard bounce
|
609
|
-
# => #<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?">
|
46
|
+
gem install postmark
|
610
47
|
```
|
611
48
|
|
612
|
-
##
|
49
|
+
## Note on Patches/Pull Requests
|
613
50
|
|
614
|
-
|
615
|
-
If you plan using it in a Rails project, check out the
|
616
|
-
[postmark-rails](https://github.com/wildbit/postmark-rails/) gem, which
|
617
|
-
is meant to integrate with ActionMailer.
|
51
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
|
618
52
|
|
619
|
-
|
620
|
-
it will attempt using the built-in Ruby Json library.
|
53
|
+
## Issues & Comments
|
621
54
|
|
622
|
-
|
55
|
+
Feel free to contact us if you encounter any issues with the library or Postmark API.
|
56
|
+
Please leave all comments, bugs, requests and issues on the Issues page.
|
623
57
|
|
624
|
-
|
625
|
-
Postmark.response_parser_class = :Json # :ActiveSupport or :Yajl are also supported.
|
626
|
-
```
|
627
|
-
|
628
|
-
## Note on Patches/Pull Requests
|
58
|
+
## License
|
629
59
|
|
630
|
-
|
631
|
-
|
632
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
633
|
-
* Commit, do not mess with rakefile, version, or history.
|
634
|
-
* Send me a pull request. Bonus points for topic branches.
|
60
|
+
The Postmark Ruby library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) license.
|
61
|
+
Refer to the [LICENSE](https://github.com/wildbit/postmark-gem/blob/master/LICENSE) file for more information.
|
635
62
|
|
636
63
|
## Copyright
|
637
64
|
|
638
|
-
Copyright ©
|
65
|
+
Copyright © 2020 Wildbit LLC.
|