resend 0.16.0 → 0.17.1
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 +4 -4
- data/lib/resend/mailer.rb +68 -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: 6a332acce7880b6cbf53de706ef39df76d4823b588b1577a6642105ca00f3649
|
4
|
+
data.tar.gz: 5fdc46d025cb2377502e6f9a5a9a4ba605f279616f36dc7e537bb79d6f0c0413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b3bbdc8c899628541a77cecb10d679afe0ca31f18bb80ad8eabedfbcdf3d7851153515387084cd003e54500fc7fa1b07f6f50a9c8a9eb9bd0d122df2199d73d
|
7
|
+
data.tar.gz: 123206e9012019d7d1274b97daeb83f5f093234ae6f0b44f6f888ed89a17d2b03d8dce234b0b811ae9e8fb6568ef1f0712d0ccc3385278a929fa09b53974916e
|
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,39 @@ 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
|
116
|
+
# remove nil header values
|
117
|
+
params.delete_if { |_k, v| v.nil? }
|
63
118
|
params
|
64
119
|
end
|
65
120
|
|
@@ -144,5 +199,16 @@ module Resend
|
|
144
199
|
end
|
145
200
|
attachments
|
146
201
|
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# Get all headers that are not ignored
|
205
|
+
#
|
206
|
+
# @param Mail mail
|
207
|
+
#
|
208
|
+
# @return Array headers
|
209
|
+
#
|
210
|
+
def unignored_headers(mail)
|
211
|
+
@unignored_headers ||= mail.header_fields.reject { |h| IGNORED_HEADERS.include?(h.name.downcase) }
|
212
|
+
end
|
147
213
|
end
|
148
214
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derich Pacheco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|