resend 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resend/mailer.rb +66 -2
- data/lib/resend/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3bd3c129bc391019cd0d3f1c30b40da0354cdc38ab1f2eb8b09830f2276afad
|
4
|
+
data.tar.gz: e7d83291e24db93d771f1a7588b5fc57353f62c86b97b5f9df1d09151f403284
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c27434e2d97b55af4a0b8bde50e5cf3c398498c460451e3ee5c367d6a78a47c8f65d3ecf7c5b7455de2a40040c4e6533b587fa7a0ee2af57d7ec262f2c2e7bf0
|
7
|
+
data.tar.gz: 671f1d0e1fb99bcfbd254ac0fa70b15c52da9406d0800188e77585be420ed7ec6ef61d8a9a4778ec03414c5275f30fb28633a17825ce7a8e110fcbb180f80c15
|
data/lib/resend/mailer.rb
CHANGED
@@ -7,6 +7,17 @@ module Resend
|
|
7
7
|
class Mailer
|
8
8
|
attr_accessor :config, :settings
|
9
9
|
|
10
|
+
# These are set as `headers` by the Rails API, but these will be filtered out
|
11
|
+
# when constructing the Resend API payload, since they're are sent as post params.
|
12
|
+
# https://resend.com/docs/api-reference/emails/send-email
|
13
|
+
IGNORED_HEADERS = %w[
|
14
|
+
cc bcc
|
15
|
+
from reply-to to subject mime-version
|
16
|
+
html text
|
17
|
+
content-type tags scheduled_at
|
18
|
+
headers
|
19
|
+
].freeze
|
20
|
+
|
10
21
|
def initialize(config)
|
11
22
|
@config = config
|
12
23
|
raise Resend::Error.new("Make sure your API Key is set", @config) unless Resend.api_key
|
@@ -51,7 +62,19 @@ module Resend
|
|
51
62
|
end
|
52
63
|
|
53
64
|
#
|
54
|
-
# Add custom headers fields
|
65
|
+
# Add custom headers fields.
|
66
|
+
#
|
67
|
+
# Both ways are supported:
|
68
|
+
#
|
69
|
+
# 1. Through the `#mail()` method ie:
|
70
|
+
# mail(headers: { "X-Custom-Header" => "value" })
|
71
|
+
#
|
72
|
+
# 2. Through the Rails `#headers` method ie:
|
73
|
+
# headers["X-Custom-Header"] = "value"
|
74
|
+
#
|
75
|
+
#
|
76
|
+
# setting the header values through the `#mail` method will overwrite values set
|
77
|
+
# through the `#headers` method using the same key.
|
55
78
|
#
|
56
79
|
# @param Mail mail Rails Mail object
|
57
80
|
#
|
@@ -59,7 +82,37 @@ module Resend
|
|
59
82
|
#
|
60
83
|
def get_headers(mail)
|
61
84
|
params = {}
|
62
|
-
|
85
|
+
|
86
|
+
if mail[:headers].present? || unignored_headers(mail).present?
|
87
|
+
params[:headers] = {}
|
88
|
+
params[:headers].merge!(headers_values(mail)) if unignored_headers(mail).present?
|
89
|
+
params[:headers].merge!(mail_headers_values(mail)) if mail[:headers].present?
|
90
|
+
end
|
91
|
+
|
92
|
+
params
|
93
|
+
end
|
94
|
+
|
95
|
+
# Gets the values of the headers that are set through the `#mail` method
|
96
|
+
#
|
97
|
+
# @param Mail mail Rails Mail object
|
98
|
+
# @return Hash hash with mail headers values
|
99
|
+
def mail_headers_values(mail)
|
100
|
+
params = {}
|
101
|
+
mail[:headers].unparsed_value.each do |k, v|
|
102
|
+
params[k.to_s] = v
|
103
|
+
end
|
104
|
+
params
|
105
|
+
end
|
106
|
+
|
107
|
+
# Gets the values of the headers that are set through the `#headers` method
|
108
|
+
#
|
109
|
+
# @param Mail mail Rails Mail object
|
110
|
+
# @return Hash hash with headers values
|
111
|
+
def headers_values(mail)
|
112
|
+
params = {}
|
113
|
+
unignored_headers(mail).each do |h|
|
114
|
+
params[h.name.to_s] = h.unparsed_value
|
115
|
+
end
|
63
116
|
params
|
64
117
|
end
|
65
118
|
|
@@ -144,5 +197,16 @@ module Resend
|
|
144
197
|
end
|
145
198
|
attachments
|
146
199
|
end
|
200
|
+
|
201
|
+
#
|
202
|
+
# Get all headers that are not ignored
|
203
|
+
#
|
204
|
+
# @param Mail mail
|
205
|
+
#
|
206
|
+
# @return Array headers
|
207
|
+
#
|
208
|
+
def unignored_headers(mail)
|
209
|
+
@unignored_headers ||= mail.header_fields.reject { |h| IGNORED_HEADERS.include?(h.name.downcase) }
|
210
|
+
end
|
147
211
|
end
|
148
212
|
end
|
data/lib/resend/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derich Pacheco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|