mandrill-rb 1.0.52 → 1.0.53
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/lib/mandrill/error.rb +62 -0
- data/lib/mandrill/exports.rb +89 -0
- data/lib/mandrill/inbound.rb +120 -0
- data/lib/mandrill/internal.rb +9 -0
- data/lib/mandrill/ips.rb +246 -0
- data/lib/mandrill/messages.rb +386 -0
- data/lib/mandrill/metadata.rb +55 -0
- data/lib/mandrill/rejects.rb +66 -0
- data/lib/mandrill/senders.rb +198 -0
- data/lib/mandrill/subaccounts.rb +157 -0
- data/lib/mandrill/tags.rb +162 -0
- data/lib/mandrill/templates.rb +219 -0
- data/lib/mandrill/urls.rb +96 -0
- data/lib/mandrill/users.rb +117 -0
- data/lib/mandrill/version.rb +3 -0
- data/lib/mandrill/webhooks.rb +112 -0
- data/lib/mandrill/whitelists.rb +43 -0
- data/mandrill-api.gemspec +22 -0
- metadata +25 -1
@@ -0,0 +1,386 @@
|
|
1
|
+
module Mandrill
|
2
|
+
class Messages
|
3
|
+
attr_accessor :master
|
4
|
+
|
5
|
+
def initialize(master)
|
6
|
+
@master = master
|
7
|
+
end
|
8
|
+
|
9
|
+
# Send a new transactional message through Mandrill
|
10
|
+
# @param [Hash] message the information on the message to send
|
11
|
+
# - [String] html the full HTML content to be sent
|
12
|
+
# - [String] text optional full text content to be sent
|
13
|
+
# - [String] subject the message subject
|
14
|
+
# - [String] from_email the sender email address.
|
15
|
+
# - [String] from_name optional from name to be used
|
16
|
+
# - [Array] to an array of recipient information.
|
17
|
+
# - [Hash] to[] a single recipient's information.
|
18
|
+
# - [String] email the email address of the recipient
|
19
|
+
# - [String] name the optional display name to use for the recipient
|
20
|
+
# - [String] type the header type to use for the recipient, defaults to "to" if not provided
|
21
|
+
# - [Hash] headers optional extra headers to add to the message (most headers are allowed)
|
22
|
+
# - [Boolean] important whether or not this message is important, and should be delivered ahead of non-important messages
|
23
|
+
# - [Boolean] track_opens whether or not to turn on open tracking for the message
|
24
|
+
# - [Boolean] track_clicks whether or not to turn on click tracking for the message
|
25
|
+
# - [Boolean] auto_text whether or not to automatically generate a text part for messages that are not given text
|
26
|
+
# - [Boolean] auto_html whether or not to automatically generate an HTML part for messages that are not given HTML
|
27
|
+
# - [Boolean] inline_css whether or not to automatically inline all CSS styles provided in the message HTML - only for HTML documents less than 256KB in size
|
28
|
+
# - [Boolean] url_strip_qs whether or not to strip the query string from URLs when aggregating tracked URL data
|
29
|
+
# - [Boolean] preserve_recipients whether or not to expose all recipients in to "To" header for each email
|
30
|
+
# - [Boolean] view_content_link set to false to remove content logging for sensitive emails
|
31
|
+
# - [String] bcc_address an optional address to receive an exact copy of each recipient's email
|
32
|
+
# - [String] tracking_domain a custom domain to use for tracking opens and clicks instead of mandrillapp.com
|
33
|
+
# - [String] signing_domain a custom domain to use for SPF/DKIM signing instead of mandrill (for "via" or "on behalf of" in email clients)
|
34
|
+
# - [String] return_path_domain a custom domain to use for the messages's return-path
|
35
|
+
# - [Boolean] merge whether to evaluate merge tags in the message. Will automatically be set to true if either merge_vars or global_merge_vars are provided.
|
36
|
+
# - [Array] global_merge_vars global merge variables to use for all recipients. You can override these per recipient.
|
37
|
+
# - [Hash] global_merge_vars[] a single global merge variable
|
38
|
+
# - [String] name the global merge variable's name. Merge variable names are case-insensitive and may not start with _
|
39
|
+
# - [String] content the global merge variable's content
|
40
|
+
# - [Array] merge_vars per-recipient merge variables, which override global merge variables with the same name.
|
41
|
+
# - [Hash] merge_vars[] per-recipient merge variables
|
42
|
+
# - [String] rcpt the email address of the recipient that the merge variables should apply to
|
43
|
+
# - [Array] vars the recipient's merge variables
|
44
|
+
# - [Hash] vars[] a single merge variable
|
45
|
+
# - [String] name the merge variable's name. Merge variable names are case-insensitive and may not start with _
|
46
|
+
# - [String] content the merge variable's content
|
47
|
+
# - [Array] tags an array of string to tag the message with. Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently. Tags should be 50 characters or less. Any tags starting with an underscore are reserved for internal use and will cause errors.
|
48
|
+
# - [String] tags[] a single tag - must not start with an underscore
|
49
|
+
# - [String] subaccount the unique id of a subaccount for this message - must already exist or will fail with an error
|
50
|
+
# - [Array] google_analytics_domains an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
|
51
|
+
# - [Array, String] google_analytics_campaign optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
|
52
|
+
# - [Array] metadata metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
|
53
|
+
# - [Array] recipient_metadata Per-recipient metadata that will override the global values specified in the metadata parameter.
|
54
|
+
# - [Hash] recipient_metadata[] metadata for a single recipient
|
55
|
+
# - [String] rcpt the email address of the recipient that the metadata is associated with
|
56
|
+
# - [Array] values an associated array containing the recipient's unique metadata. If a key exists in both the per-recipient metadata and the global metadata, the per-recipient metadata will be used.
|
57
|
+
# - [Array] attachments an array of supported attachments to add to the message
|
58
|
+
# - [Hash] attachments[] a single supported attachment
|
59
|
+
# - [String] type the MIME type of the attachment
|
60
|
+
# - [String] name the file name of the attachment
|
61
|
+
# - [String] content the content of the attachment as a base64-encoded string
|
62
|
+
# - [Array] images an array of embedded images to add to the message
|
63
|
+
# - [Hash] images[] a single embedded image
|
64
|
+
# - [String] type the MIME type of the image - must start with "image/"
|
65
|
+
# - [String] name the Content ID of the image - use <img src="cid:THIS_VALUE"> to reference the image in your HTML content
|
66
|
+
# - [String] content the content of the image as a base64-encoded string
|
67
|
+
# @param [Boolean] async enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.
|
68
|
+
# @param [String] ip_pool the name of the dedicated ip pool that should be used to send the message. If you do not have any dedicated IPs, this parameter has no effect. If you specify a pool that does not exist, your default pool will be used instead.
|
69
|
+
# @param [String] send_at when this message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately. An additional fee applies for scheduled email, and this feature is only available to accounts with a positive balance.
|
70
|
+
# @return [Array] of structs for each recipient containing the key "email" with the email address, and details of the message status for that recipient
|
71
|
+
# - [Hash] return[] the sending results for a single recipient
|
72
|
+
# - [String] email the email address of the recipient
|
73
|
+
# - [String] status the sending status of the recipient - either "sent", "queued", "scheduled", "rejected", or "invalid"
|
74
|
+
# - [String] reject_reason the reason for the rejection if the recipient status is "rejected" - one of "hard-bounce", "soft-bounce", "spam", "unsub", "custom", "invalid-sender", "invalid", "test-mode-limit", or "rule"
|
75
|
+
# - [String] _id the message's unique id
|
76
|
+
def send(message, async=false, ip_pool=nil, send_at=nil)
|
77
|
+
_params = {:message => message, :async => async, :ip_pool => ip_pool, :send_at => send_at}
|
78
|
+
return @master.call 'messages/send', _params
|
79
|
+
end
|
80
|
+
|
81
|
+
# Send a new transactional message through Mandrill using a template
|
82
|
+
# @param [String] template_name the immutable name or slug of a template that exists in the user's account. For backwards-compatibility, the template name may also be used but the immutable slug is preferred.
|
83
|
+
# @param [Array] template_content an array of template content to send. Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block
|
84
|
+
# - [Hash] template_content[] the injection of a single piece of content into a single editable region
|
85
|
+
# - [String] name the name of the mc:edit editable region to inject into
|
86
|
+
# - [String] content the content to inject
|
87
|
+
# @param [Hash] message the other information on the message to send - same as /messages/send, but without the html content
|
88
|
+
# - [String] html optional full HTML content to be sent if not in template
|
89
|
+
# - [String] text optional full text content to be sent
|
90
|
+
# - [String] subject the message subject
|
91
|
+
# - [String] from_email the sender email address.
|
92
|
+
# - [String] from_name optional from name to be used
|
93
|
+
# - [Array] to an array of recipient information.
|
94
|
+
# - [Hash] to[] a single recipient's information.
|
95
|
+
# - [String] email the email address of the recipient
|
96
|
+
# - [String] name the optional display name to use for the recipient
|
97
|
+
# - [String] type the header type to use for the recipient, defaults to "to" if not provided
|
98
|
+
# - [Hash] headers optional extra headers to add to the message (most headers are allowed)
|
99
|
+
# - [Boolean] important whether or not this message is important, and should be delivered ahead of non-important messages
|
100
|
+
# - [Boolean] track_opens whether or not to turn on open tracking for the message
|
101
|
+
# - [Boolean] track_clicks whether or not to turn on click tracking for the message
|
102
|
+
# - [Boolean] auto_text whether or not to automatically generate a text part for messages that are not given text
|
103
|
+
# - [Boolean] auto_html whether or not to automatically generate an HTML part for messages that are not given HTML
|
104
|
+
# - [Boolean] inline_css whether or not to automatically inline all CSS styles provided in the message HTML - only for HTML documents less than 256KB in size
|
105
|
+
# - [Boolean] url_strip_qs whether or not to strip the query string from URLs when aggregating tracked URL data
|
106
|
+
# - [Boolean] preserve_recipients whether or not to expose all recipients in to "To" header for each email
|
107
|
+
# - [Boolean] view_content_link set to false to remove content logging for sensitive emails
|
108
|
+
# - [String] bcc_address an optional address to receive an exact copy of each recipient's email
|
109
|
+
# - [String] tracking_domain a custom domain to use for tracking opens and clicks instead of mandrillapp.com
|
110
|
+
# - [String] signing_domain a custom domain to use for SPF/DKIM signing instead of mandrill (for "via" or "on behalf of" in email clients)
|
111
|
+
# - [String] return_path_domain a custom domain to use for the messages's return-path
|
112
|
+
# - [Boolean] merge whether to evaluate merge tags in the message. Will automatically be set to true if either merge_vars or global_merge_vars are provided.
|
113
|
+
# - [Array] global_merge_vars global merge variables to use for all recipients. You can override these per recipient.
|
114
|
+
# - [Hash] global_merge_vars[] a single global merge variable
|
115
|
+
# - [String] name the global merge variable's name. Merge variable names are case-insensitive and may not start with _
|
116
|
+
# - [String] content the global merge variable's content
|
117
|
+
# - [Array] merge_vars per-recipient merge variables, which override global merge variables with the same name.
|
118
|
+
# - [Hash] merge_vars[] per-recipient merge variables
|
119
|
+
# - [String] rcpt the email address of the recipient that the merge variables should apply to
|
120
|
+
# - [Array] vars the recipient's merge variables
|
121
|
+
# - [Hash] vars[] a single merge variable
|
122
|
+
# - [String] name the merge variable's name. Merge variable names are case-insensitive and may not start with _
|
123
|
+
# - [String] content the merge variable's content
|
124
|
+
# - [Array] tags an array of string to tag the message with. Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently. Tags should be 50 characters or less. Any tags starting with an underscore are reserved for internal use and will cause errors.
|
125
|
+
# - [String] tags[] a single tag - must not start with an underscore
|
126
|
+
# - [String] subaccount the unique id of a subaccount for this message - must already exist or will fail with an error
|
127
|
+
# - [Array] google_analytics_domains an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.
|
128
|
+
# - [Array, String] google_analytics_campaign optional string indicating the value to set for the utm_campaign tracking parameter. If this isn't provided the email's from address will be used instead.
|
129
|
+
# - [Array] metadata metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.
|
130
|
+
# - [Array] recipient_metadata Per-recipient metadata that will override the global values specified in the metadata parameter.
|
131
|
+
# - [Hash] recipient_metadata[] metadata for a single recipient
|
132
|
+
# - [String] rcpt the email address of the recipient that the metadata is associated with
|
133
|
+
# - [Array] values an associated array containing the recipient's unique metadata. If a key exists in both the per-recipient metadata and the global metadata, the per-recipient metadata will be used.
|
134
|
+
# - [Array] attachments an array of supported attachments to add to the message
|
135
|
+
# - [Hash] attachments[] a single supported attachment
|
136
|
+
# - [String] type the MIME type of the attachment
|
137
|
+
# - [String] name the file name of the attachment
|
138
|
+
# - [String] content the content of the attachment as a base64-encoded string
|
139
|
+
# - [Array] images an array of embedded images to add to the message
|
140
|
+
# - [Hash] images[] a single embedded image
|
141
|
+
# - [String] type the MIME type of the image - must start with "image/"
|
142
|
+
# - [String] name the Content ID of the image - use <img src="cid:THIS_VALUE"> to reference the image in your HTML content
|
143
|
+
# - [String] content the content of the image as a base64-encoded string
|
144
|
+
# @param [Boolean] async enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.
|
145
|
+
# @param [String] ip_pool the name of the dedicated ip pool that should be used to send the message. If you do not have any dedicated IPs, this parameter has no effect. If you specify a pool that does not exist, your default pool will be used instead.
|
146
|
+
# @param [String] send_at when this message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately. An additional fee applies for scheduled email, and this feature is only available to accounts with a positive balance.
|
147
|
+
# @return [Array] of structs for each recipient containing the key "email" with the email address, and details of the message status for that recipient
|
148
|
+
# - [Hash] return[] the sending results for a single recipient
|
149
|
+
# - [String] email the email address of the recipient
|
150
|
+
# - [String] status the sending status of the recipient - either "sent", "queued", "rejected", or "invalid"
|
151
|
+
# - [String] reject_reason the reason for the rejection if the recipient status is "rejected" - one of "hard-bounce", "soft-bounce", "spam", "unsub", "custom", "invalid-sender", "invalid", "test-mode-limit", or "rule"
|
152
|
+
# - [String] _id the message's unique id
|
153
|
+
def send_template(template_name, template_content, message, async=false, ip_pool=nil, send_at=nil)
|
154
|
+
_params = {:template_name => template_name, :template_content => template_content, :message => message, :async => async, :ip_pool => ip_pool, :send_at => send_at}
|
155
|
+
return @master.call 'messages/send-template', _params
|
156
|
+
end
|
157
|
+
|
158
|
+
# Search recently sent messages and optionally narrow by date range, tags, senders, and API keys. If no date range is specified, results within the last 7 days are returned. This method may be called up to 20 times per minute. If you need the data more often, you can use <a href="/api/docs/messages.html#method=info">/messages/info.json</a> to get the information for a single message, or <a href="http://help.mandrill.com/entries/21738186-Introduction-to-Webhooks">webhooks</a> to push activity to your own application for querying.
|
159
|
+
# @param [String] query <a href="http://help.mandrill.com/entries/22211902">search terms</a> to find matching messages
|
160
|
+
# @param [String] date_from start date
|
161
|
+
# @param [String] date_to end date
|
162
|
+
# @param [Array] tags an array of tag names to narrow the search to, will return messages that contain ANY of the tags
|
163
|
+
# @param [Array] senders an array of sender addresses to narrow the search to, will return messages sent by ANY of the senders
|
164
|
+
# @param [Array] api_keys an array of API keys to narrow the search to, will return messages sent by ANY of the keys
|
165
|
+
# @param [Integer] limit the maximum number of results to return, defaults to 100, 1000 is the maximum
|
166
|
+
# @return [Array] of structs for each matching message
|
167
|
+
# - [Hash] return[] the information for a single matching message
|
168
|
+
# - [Integer] ts the Unix timestamp from when this message was sent
|
169
|
+
# - [String] _id the message's unique id
|
170
|
+
# - [String] sender the email address of the sender
|
171
|
+
# - [String] template the unique name of the template used, if any
|
172
|
+
# - [String] subject the message's subject line
|
173
|
+
# - [String] email the recipient email address
|
174
|
+
# - [Array] tags list of tags on this message
|
175
|
+
# - [String] tags[] individual tag on this message
|
176
|
+
# - [Integer] opens how many times has this message been opened
|
177
|
+
# - [Array] opens_detail list of individual opens for the message
|
178
|
+
# - [Hash] opens_detail[] information on an individual open
|
179
|
+
# - [Integer] ts the unix timestamp from when the message was opened
|
180
|
+
# - [String] ip the IP address that generated the open
|
181
|
+
# - [String] location the approximate region and country that the opening IP is located
|
182
|
+
# - [String] ua the email client or browser data of the open
|
183
|
+
# - [Integer] clicks how many times has a link been clicked in this message
|
184
|
+
# - [Array] clicks_detail list of individual clicks for the message
|
185
|
+
# - [Hash] clicks_detail[] information on an individual click
|
186
|
+
# - [Integer] ts the unix timestamp from when the message was clicked
|
187
|
+
# - [String] url the URL that was clicked on
|
188
|
+
# - [String] ip the IP address that generated the click
|
189
|
+
# - [String] location the approximate region and country that the clicking IP is located
|
190
|
+
# - [String] ua the email client or browser data of the click
|
191
|
+
# - [String] state sending status of this message: sent, bounced, rejected
|
192
|
+
# - [Hash] metadata any custom metadata provided when the message was sent
|
193
|
+
# - [Array] smtp_events a log of up to 3 smtp events for the message
|
194
|
+
# - [Hash] smtp_events[] information about a specific smtp event
|
195
|
+
# - [Integer] ts the Unix timestamp when the event occured
|
196
|
+
# - [String] type the message's state as a result of this event
|
197
|
+
# - [String] diag the SMTP response from the recipient's server
|
198
|
+
def search(query='*', date_from=nil, date_to=nil, tags=nil, senders=nil, api_keys=nil, limit=100)
|
199
|
+
_params = {:query => query, :date_from => date_from, :date_to => date_to, :tags => tags, :senders => senders, :api_keys => api_keys, :limit => limit}
|
200
|
+
return @master.call 'messages/search', _params
|
201
|
+
end
|
202
|
+
|
203
|
+
# Search the content of recently sent messages and return the aggregated hourly stats for matching messages
|
204
|
+
# @param [String] query the search terms to find matching messages for
|
205
|
+
# @param [String] date_from start date
|
206
|
+
# @param [String] date_to end date
|
207
|
+
# @param [Array] tags an array of tag names to narrow the search to, will return messages that contain ANY of the tags
|
208
|
+
# @param [Array] senders an array of sender addresses to narrow the search to, will return messages sent by ANY of the senders
|
209
|
+
# @return [Array] the array of history information
|
210
|
+
# - [Hash] return[] the stats for a single hour
|
211
|
+
# - [String] time the hour as a UTC date string in YYYY-MM-DD HH:MM:SS format
|
212
|
+
# - [Integer] sent the number of emails that were sent during the hour
|
213
|
+
# - [Integer] hard_bounces the number of emails that hard bounced during the hour
|
214
|
+
# - [Integer] soft_bounces the number of emails that soft bounced during the hour
|
215
|
+
# - [Integer] rejects the number of emails that were rejected during the hour
|
216
|
+
# - [Integer] complaints the number of spam complaints received during the hour
|
217
|
+
# - [Integer] unsubs the number of unsubscribes received during the hour
|
218
|
+
# - [Integer] opens the number of emails opened during the hour
|
219
|
+
# - [Integer] unique_opens the number of unique opens generated by messages sent during the hour
|
220
|
+
# - [Integer] clicks the number of tracked URLs clicked during the hour
|
221
|
+
# - [Integer] unique_clicks the number of unique clicks generated by messages sent during the hour
|
222
|
+
def search_time_series(query='*', date_from=nil, date_to=nil, tags=nil, senders=nil)
|
223
|
+
_params = {:query => query, :date_from => date_from, :date_to => date_to, :tags => tags, :senders => senders}
|
224
|
+
return @master.call 'messages/search-time-series', _params
|
225
|
+
end
|
226
|
+
|
227
|
+
# Get the information for a single recently sent message
|
228
|
+
# @param [String] id the unique id of the message to get - passed as the "_id" field in webhooks, send calls, or search calls
|
229
|
+
# @return [Hash] the information for the message
|
230
|
+
# - [Integer] ts the Unix timestamp from when this message was sent
|
231
|
+
# - [String] _id the message's unique id
|
232
|
+
# - [String] sender the email address of the sender
|
233
|
+
# - [String] template the unique name of the template used, if any
|
234
|
+
# - [String] subject the message's subject line
|
235
|
+
# - [String] email the recipient email address
|
236
|
+
# - [Array] tags list of tags on this message
|
237
|
+
# - [String] tags[] individual tag on this message
|
238
|
+
# - [Integer] opens how many times has this message been opened
|
239
|
+
# - [Array] opens_detail list of individual opens for the message
|
240
|
+
# - [Hash] opens_detail[] information on an individual open
|
241
|
+
# - [Integer] ts the unix timestamp from when the message was opened
|
242
|
+
# - [String] ip the IP address that generated the open
|
243
|
+
# - [String] location the approximate region and country that the opening IP is located
|
244
|
+
# - [String] ua the email client or browser data of the open
|
245
|
+
# - [Integer] clicks how many times has a link been clicked in this message
|
246
|
+
# - [Array] clicks_detail list of individual clicks for the message
|
247
|
+
# - [Hash] clicks_detail[] information on an individual click
|
248
|
+
# - [Integer] ts the unix timestamp from when the message was clicked
|
249
|
+
# - [String] url the URL that was clicked on
|
250
|
+
# - [String] ip the IP address that generated the click
|
251
|
+
# - [String] location the approximate region and country that the clicking IP is located
|
252
|
+
# - [String] ua the email client or browser data of the click
|
253
|
+
# - [String] state sending status of this message: sent, bounced, rejected
|
254
|
+
# - [Hash] metadata any custom metadata provided when the message was sent
|
255
|
+
# - [Array] smtp_events a log of up to 3 smtp events for the message
|
256
|
+
# - [Hash] smtp_events[] information about a specific smtp event
|
257
|
+
# - [Integer] ts the Unix timestamp when the event occured
|
258
|
+
# - [String] type the message's state as a result of this event
|
259
|
+
# - [String] diag the SMTP response from the recipient's server
|
260
|
+
def info(id)
|
261
|
+
_params = {:id => id}
|
262
|
+
return @master.call 'messages/info', _params
|
263
|
+
end
|
264
|
+
|
265
|
+
# Get the full content of a recently sent message
|
266
|
+
# @param [String] id the unique id of the message to get - passed as the "_id" field in webhooks, send calls, or search calls
|
267
|
+
# @return [Hash] the content of the message
|
268
|
+
# - [Integer] ts the Unix timestamp from when this message was sent
|
269
|
+
# - [String] _id the message's unique id
|
270
|
+
# - [String] from_email the email address of the sender
|
271
|
+
# - [String] from_name the alias of the sender (if any)
|
272
|
+
# - [String] subject the message's subject line
|
273
|
+
# - [Hash] to the message recipient's information
|
274
|
+
# - [String] email the email address of the recipient
|
275
|
+
# - [String] name the alias of the recipient (if any)
|
276
|
+
# - [Array] tags list of tags on this message
|
277
|
+
# - [String] tags[] individual tag on this message
|
278
|
+
# - [Hash] headers the key-value pairs of the custom MIME headers for the message's main document
|
279
|
+
# - [String] text the text part of the message, if any
|
280
|
+
# - [String] html the HTML part of the message, if any
|
281
|
+
# - [Array] attachments an array of any attachments that can be found in the message
|
282
|
+
# - [Hash] attachments[] information about an individual attachment
|
283
|
+
# - [String] name the file name of the attachment
|
284
|
+
# - [String] type the MIME type of the attachment
|
285
|
+
# - [String] content the content of the attachment as a base64 encoded string
|
286
|
+
def content(id)
|
287
|
+
_params = {:id => id}
|
288
|
+
return @master.call 'messages/content', _params
|
289
|
+
end
|
290
|
+
|
291
|
+
# Parse the full MIME document for an email message, returning the content of the message broken into its constituent pieces
|
292
|
+
# @param [String] raw_message the full MIME document of an email message
|
293
|
+
# @return [Hash] the parsed message
|
294
|
+
# - [String] subject the subject of the message
|
295
|
+
# - [String] from_email the email address of the sender
|
296
|
+
# - [String] from_name the alias of the sender (if any)
|
297
|
+
# - [Array] to an array of any recipients in the message
|
298
|
+
# - [Hash] to[] the information on a single recipient
|
299
|
+
# - [String] email the email address of the recipient
|
300
|
+
# - [String] name the alias of the recipient (if any)
|
301
|
+
# - [Hash] headers the key-value pairs of the MIME headers for the message's main document
|
302
|
+
# - [String] text the text part of the message, if any
|
303
|
+
# - [String] html the HTML part of the message, if any
|
304
|
+
# - [Array] attachments an array of any attachments that can be found in the message
|
305
|
+
# - [Hash] attachments[] information about an individual attachment
|
306
|
+
# - [String] name the file name of the attachment
|
307
|
+
# - [String] type the MIME type of the attachment
|
308
|
+
# - [Boolean] binary if this is set to true, the attachment is not pure-text, and the content will be base64 encoded
|
309
|
+
# - [String] content the content of the attachment as a text string or a base64 encoded string based on the attachment type
|
310
|
+
# - [Array] images an array of any embedded images that can be found in the message
|
311
|
+
# - [Hash] images[] information about an individual image
|
312
|
+
# - [String] name the Content-ID of the embedded image
|
313
|
+
# - [String] type the MIME type of the image
|
314
|
+
# - [String] content the content of the image as a base64 encoded string
|
315
|
+
def parse(raw_message)
|
316
|
+
_params = {:raw_message => raw_message}
|
317
|
+
return @master.call 'messages/parse', _params
|
318
|
+
end
|
319
|
+
|
320
|
+
# Take a raw MIME document for a message, and send it exactly as if it were sent through Mandrill's SMTP servers
|
321
|
+
# @param [String] raw_message the full MIME document of an email message
|
322
|
+
# @param [String, nil] from_email optionally define the sender address - otherwise we'll use the address found in the provided headers
|
323
|
+
# @param [String, nil] from_name optionally define the sender alias
|
324
|
+
# @param [Array, nil] to optionally define the recipients to receive the message - otherwise we'll use the To, Cc, and Bcc headers provided in the document
|
325
|
+
# - [String] to[] the email address of the recipient
|
326
|
+
# @param [Boolean] async enable a background sending mode that is optimized for bulk sending. In async mode, messages/sendRaw will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.
|
327
|
+
# @param [String] ip_pool the name of the dedicated ip pool that should be used to send the message. If you do not have any dedicated IPs, this parameter has no effect. If you specify a pool that does not exist, your default pool will be used instead.
|
328
|
+
# @param [String] send_at when this message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately.
|
329
|
+
# @param [String] return_path_domain a custom domain to use for the messages's return-path
|
330
|
+
# @return [Array] of structs for each recipient containing the key "email" with the email address, and details of the message status for that recipient
|
331
|
+
# - [Hash] return[] the sending results for a single recipient
|
332
|
+
# - [String] email the email address of the recipient
|
333
|
+
# - [String] status the sending status of the recipient - either "sent", "queued", "scheduled", "rejected", or "invalid"
|
334
|
+
# - [String] reject_reason the reason for the rejection if the recipient status is "rejected" - one of "hard-bounce", "soft-bounce", "spam", "unsub", "custom", "invalid-sender", "invalid", "test-mode-limit", or "rule"
|
335
|
+
# - [String] _id the message's unique id
|
336
|
+
def send_raw(raw_message, from_email=nil, from_name=nil, to=nil, async=false, ip_pool=nil, send_at=nil, return_path_domain=nil)
|
337
|
+
_params = {:raw_message => raw_message, :from_email => from_email, :from_name => from_name, :to => to, :async => async, :ip_pool => ip_pool, :send_at => send_at, :return_path_domain => return_path_domain}
|
338
|
+
return @master.call 'messages/send-raw', _params
|
339
|
+
end
|
340
|
+
|
341
|
+
# Queries your scheduled emails by sender or recipient, or both.
|
342
|
+
# @param [String] to an optional recipient address to restrict results to
|
343
|
+
# @return [Array] a list of up to 1000 scheduled emails
|
344
|
+
# - [Hash] return[] a scheduled email
|
345
|
+
# - [String] _id the scheduled message id
|
346
|
+
# - [String] created_at the UTC timestamp when the message was created, in YYYY-MM-DD HH:MM:SS format
|
347
|
+
# - [String] send_at the UTC timestamp when the message will be sent, in YYYY-MM-DD HH:MM:SS format
|
348
|
+
# - [String] from_email the email's sender address
|
349
|
+
# - [String] to the email's recipient
|
350
|
+
# - [String] subject the email's subject
|
351
|
+
def list_scheduled(to=nil)
|
352
|
+
_params = {:to => to}
|
353
|
+
return @master.call 'messages/list-scheduled', _params
|
354
|
+
end
|
355
|
+
|
356
|
+
# Cancels a scheduled email.
|
357
|
+
# @param [String] id a scheduled email id, as returned by any of the messages/send calls or messages/list-scheduled
|
358
|
+
# @return [Hash] information about the scheduled email that was cancelled.
|
359
|
+
# - [String] _id the scheduled message id
|
360
|
+
# - [String] created_at the UTC timestamp when the message was created, in YYYY-MM-DD HH:MM:SS format
|
361
|
+
# - [String] send_at the UTC timestamp when the message will be sent, in YYYY-MM-DD HH:MM:SS format
|
362
|
+
# - [String] from_email the email's sender address
|
363
|
+
# - [String] to the email's recipient
|
364
|
+
# - [String] subject the email's subject
|
365
|
+
def cancel_scheduled(id)
|
366
|
+
_params = {:id => id}
|
367
|
+
return @master.call 'messages/cancel-scheduled', _params
|
368
|
+
end
|
369
|
+
|
370
|
+
# Reschedules a scheduled email.
|
371
|
+
# @param [String] id a scheduled email id, as returned by any of the messages/send calls or messages/list-scheduled
|
372
|
+
# @param [String] send_at the new UTC timestamp when the message should sent. Mandrill can't time travel, so if you specify a time in past the message will be sent immediately
|
373
|
+
# @return [Hash] information about the scheduled email that was rescheduled.
|
374
|
+
# - [String] _id the scheduled message id
|
375
|
+
# - [String] created_at the UTC timestamp when the message was created, in YYYY-MM-DD HH:MM:SS format
|
376
|
+
# - [String] send_at the UTC timestamp when the message will be sent, in YYYY-MM-DD HH:MM:SS format
|
377
|
+
# - [String] from_email the email's sender address
|
378
|
+
# - [String] to the email's recipient
|
379
|
+
# - [String] subject the email's subject
|
380
|
+
def reschedule(id, send_at)
|
381
|
+
_params = {:id => id, :send_at => send_at}
|
382
|
+
return @master.call 'messages/reschedule', _params
|
383
|
+
end
|
384
|
+
|
385
|
+
end
|
386
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Mandrill
|
2
|
+
class Metadata
|
3
|
+
attr_accessor :master
|
4
|
+
|
5
|
+
def initialize(master)
|
6
|
+
@master = master
|
7
|
+
end
|
8
|
+
|
9
|
+
# Get the list of custom metadata fields indexed for the account.
|
10
|
+
# @return [Array] the custom metadata fields for the account
|
11
|
+
# - [Hash] return[] the individual custom metadata field info
|
12
|
+
# - [String] name the unique identifier of the metadata field to update
|
13
|
+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
|
14
|
+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
|
15
|
+
def list()
|
16
|
+
_params = {}
|
17
|
+
return @master.call 'metadata/list', _params
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add a new custom metadata field to be indexed for the account.
|
21
|
+
# @param [String] name a unique identifier for the metadata field
|
22
|
+
# @param [String] view_template optional Mustache template to control how the metadata is rendered in your activity log
|
23
|
+
# @return [Hash] the information saved about the new metadata field
|
24
|
+
# - [String] name the unique identifier of the metadata field to update
|
25
|
+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
|
26
|
+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
|
27
|
+
def add(name, view_template=nil)
|
28
|
+
_params = {:name => name, :view_template => view_template}
|
29
|
+
return @master.call 'metadata/add', _params
|
30
|
+
end
|
31
|
+
|
32
|
+
# Update an existing custom metadata field.
|
33
|
+
# @param [String] name the unique identifier of the metadata field to update
|
34
|
+
# @param [String] view_template optional Mustache template to control how the metadata is rendered in your activity log
|
35
|
+
# @return [Hash] the information for the updated metadata field
|
36
|
+
# - [String] name the unique identifier of the metadata field to update
|
37
|
+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
|
38
|
+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
|
39
|
+
def update(name, view_template)
|
40
|
+
_params = {:name => name, :view_template => view_template}
|
41
|
+
return @master.call 'metadata/update', _params
|
42
|
+
end
|
43
|
+
|
44
|
+
# Delete an existing custom metadata field. Deletion isn't instataneous, and /metadata/list will continue to return the field until the asynchronous deletion process is complete.
|
45
|
+
# @param [String] name the unique identifier of the metadata field to update
|
46
|
+
# @return [Hash] the information for the deleted metadata field
|
47
|
+
# - [String] name the unique identifier of the metadata field to update
|
48
|
+
# - [String] state the current state of the metadata field, one of "active", "delete", or "index"
|
49
|
+
# - [String] view_template Mustache template to control how the metadata is rendered in your activity log
|
50
|
+
def delete(name)
|
51
|
+
_params = {:name => name}
|
52
|
+
return @master.call 'metadata/delete', _params
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Mandrill
|
2
|
+
class Rejects
|
3
|
+
attr_accessor :master
|
4
|
+
|
5
|
+
def initialize(master)
|
6
|
+
@master = master
|
7
|
+
end
|
8
|
+
|
9
|
+
# Adds an email to your email rejection blacklist. Addresses that you add manually will never expire and there is no reputation penalty for removing them from your blacklist. Attempting to blacklist an address that has been whitelisted will have no effect.
|
10
|
+
# @param [String] email an email address to block
|
11
|
+
# @param [String] comment an optional comment describing the rejection
|
12
|
+
# @param [String] subaccount an optional unique identifier for the subaccount to limit the blacklist entry
|
13
|
+
# @return [Hash] a status object containing the address and the result of the operation
|
14
|
+
# - [String] email the email address you provided
|
15
|
+
# - [Boolean] added whether the operation succeeded
|
16
|
+
def add(email, comment=nil, subaccount=nil)
|
17
|
+
_params = {:email => email, :comment => comment, :subaccount => subaccount}
|
18
|
+
return @master.call 'rejects/add', _params
|
19
|
+
end
|
20
|
+
|
21
|
+
# Retrieves your email rejection blacklist. You can provide an email address to limit the results. Returns up to 1000 results. By default, entries that have expired are excluded from the results; set include_expired to true to include them.
|
22
|
+
# @param [String] email an optional email address to search by
|
23
|
+
# @param [Boolean] include_expired whether to include rejections that have already expired.
|
24
|
+
# @param [String] subaccount an optional unique identifier for the subaccount to limit the blacklist
|
25
|
+
# @return [Array] Up to 1000 rejection entries
|
26
|
+
# - [Hash] return[] the information for each rejection blacklist entry
|
27
|
+
# - [String] email the email that is blocked
|
28
|
+
# - [String] reason the type of event (hard-bounce, soft-bounce, spam, unsub, custom) that caused this rejection
|
29
|
+
# - [String] detail extended details about the event, such as the SMTP diagnostic for bounces or the comment for manually-created rejections
|
30
|
+
# - [String] created_at when the email was added to the blacklist
|
31
|
+
# - [String] last_event_at the timestamp of the most recent event that either created or renewed this rejection
|
32
|
+
# - [String] expires_at when the blacklist entry will expire (this may be in the past)
|
33
|
+
# - [Boolean] expired whether the blacklist entry has expired
|
34
|
+
# - [Hash] sender the sender that this blacklist entry applies to, or null if none.
|
35
|
+
# - [String] address the sender's email address
|
36
|
+
# - [String] created_at the date and time that the sender was first seen by Mandrill as a UTC date string in YYYY-MM-DD HH:MM:SS format
|
37
|
+
# - [Integer] sent the total number of messages sent by this sender
|
38
|
+
# - [Integer] hard_bounces the total number of hard bounces by messages by this sender
|
39
|
+
# - [Integer] soft_bounces the total number of soft bounces by messages by this sender
|
40
|
+
# - [Integer] rejects the total number of rejected messages by this sender
|
41
|
+
# - [Integer] complaints the total number of spam complaints received for messages by this sender
|
42
|
+
# - [Integer] unsubs the total number of unsubscribe requests received for messages by this sender
|
43
|
+
# - [Integer] opens the total number of times messages by this sender have been opened
|
44
|
+
# - [Integer] clicks the total number of times tracked URLs in messages by this sender have been clicked
|
45
|
+
# - [Integer] unique_opens the number of unique opens for emails sent for this sender
|
46
|
+
# - [Integer] unique_clicks the number of unique clicks for emails sent for this sender
|
47
|
+
# - [String] subaccount the subaccount that this blacklist entry applies to, or null if none.
|
48
|
+
def list(email=nil, include_expired=false, subaccount=nil)
|
49
|
+
_params = {:email => email, :include_expired => include_expired, :subaccount => subaccount}
|
50
|
+
return @master.call 'rejects/list', _params
|
51
|
+
end
|
52
|
+
|
53
|
+
# Deletes an email rejection. There is no limit to how many rejections you can remove from your blacklist, but keep in mind that each deletion has an affect on your reputation.
|
54
|
+
# @param [String] email an email address
|
55
|
+
# @param [String] subaccount an optional unique identifier for the subaccount to limit the blacklist deletion
|
56
|
+
# @return [Hash] a status object containing the address and whether the deletion succeeded.
|
57
|
+
# - [String] email the email address that was removed from the blacklist
|
58
|
+
# - [Boolean] deleted whether the address was deleted successfully.
|
59
|
+
# - [String] subaccount the subaccount blacklist that the address was removed from, if any
|
60
|
+
def delete(email, subaccount=nil)
|
61
|
+
_params = {:email => email, :subaccount => subaccount}
|
62
|
+
return @master.call 'rejects/delete', _params
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|