send_grid_mailer 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e3fa23b9b575573326846fa176dd083c30ed49dcf5ce0ec66e84c2bc8047f89
4
- data.tar.gz: 7fa6d5f79c907071538743b70660fa7a1a1d3d86b5afee72ec717a49a9c625ef
3
+ metadata.gz: d3ba49658ee4d361ee0447235860596bfbda468304436ef9853ef240fb578aae
4
+ data.tar.gz: 578c91e30a4aadc8c6399eab270a661f6d319e60a3197033a1018bd6fcfb5fe4
5
5
  SHA512:
6
- metadata.gz: 974cbcd80e0341014b804e55a16855fc089577a6eb64c1c382a6a364d08613da0b43359f55965d58ea2ce9907bc7a505d18b5046273283e98193690593cb6f1d
7
- data.tar.gz: 968499dbdba06c2c2d23b05e04ec1eccd042d9c2f923f3c0a8dbc6785c3a5aad786bc897db0b80e7f4fc14cc6459a6811e70762f6c0b5e5de1527604f8d0bc90
6
+ metadata.gz: 077a40754df2f0004cf2dc8feff8583b927a644d69acbd67fbf200bbce7d1c3a1edd32f49594f79f0a8808b1d1a672ff67952cfae0a30cca2497d86d5e2a15b4
7
+ data.tar.gz: 56849b81c28093d0fadcc07e24abe1912a5e3291330d29f3c929f54e117776add2af462e6c8d5533f3fb3e459b8ea34f3def59eaeb038c827d2b065cade5355f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ### v2.4.0
6
+
7
+ #### Added
8
+
9
+ * Add the set_reply_to method to enable setting the Reply-To header. [#28] thanks @m-quezada-loyola
10
+
5
11
  ### v2.3.0
6
12
 
7
13
  ##### Added
@@ -6,6 +6,7 @@ module SendGridMailer
6
6
  :set_template_id,
7
7
  :set_sender,
8
8
  :set_recipients,
9
+ :set_reply_to,
9
10
  :set_subject,
10
11
  :set_content,
11
12
  :add_attachment,
@@ -30,16 +31,10 @@ module SendGridMailer
30
31
  end
31
32
 
32
33
  def set_sender(email)
33
- return unless email
34
-
35
- matched_format = email.match(/<(.+)>/)
36
- if matched_format
37
- address = matched_format[1]
38
- name = email.match(/\"?([^<^\"]*)\"?\s?/)[1].strip
39
- mail.from = SendGrid::Email.new(email: address, name: name)
40
- else
41
- mail.from = SendGrid::Email.new(email: email)
42
- end
34
+ email_info = extract_email_and_name(email)
35
+ return unless email_info
36
+
37
+ mail.from = SendGrid::Email.new(email: email_info[:email], name: email_info[:name])
43
38
  end
44
39
 
45
40
  def set_recipients(mode, *emails)
@@ -50,6 +45,13 @@ module SendGridMailer
50
45
  end
51
46
  end
52
47
 
48
+ def set_reply_to(email)
49
+ email_info = extract_email_and_name(email)
50
+ return unless email_info
51
+
52
+ mail.reply_to = SendGrid::Email.new(email: email_info[:email], name: email_info[:name])
53
+ end
54
+
53
55
  def set_subject(value)
54
56
  return unless value
55
57
 
@@ -94,6 +96,19 @@ module SendGridMailer
94
96
  @mail ||= SendGrid::Mail.new
95
97
  end
96
98
 
99
+ def extract_email_and_name(email)
100
+ return unless email
101
+
102
+ matched_format = email.match(/<(.+)>/)
103
+ if matched_format
104
+ address = matched_format[1]
105
+ name = email.match(/\"?([^<^\"]*)\"?\s?/)[1].strip
106
+ { email: address, name: name }
107
+ else
108
+ { email: email }
109
+ end
110
+ end
111
+
97
112
  def clean_recipients(mode)
98
113
  personalization.instance_variable_set("@#{mode}s", [])
99
114
  end
@@ -108,6 +123,8 @@ module SendGridMailer
108
123
 
109
124
  def sender?; mail.from.present? end
110
125
 
126
+ def reply_to?; mail.reply_to.present? end
127
+
111
128
  def subject?; personalization.subject.present? end
112
129
 
113
130
  def template_id?; mail.template_id.present? end
@@ -65,6 +65,7 @@ module SendGridMailer
65
65
  m.to = emails(:tos) if emails(:tos).present?
66
66
  m.cc = emails(:ccs) if emails(:ccs).present?
67
67
  m.bcc = emails(:bccs) if emails(:bccs).present?
68
+ m.reply_to = @sg_definition.mail.reply_to["email"] if @sg_definition.mail.reply_to.present?
68
69
 
69
70
  m
70
71
  end
@@ -33,6 +33,7 @@ module ActionMailer
33
33
  set_recipients(:to, params[:to])
34
34
  set_recipients(:cc, params[:cc])
35
35
  set_recipients(:bcc, params[:bcc])
36
+ set_reply_to(params[:reply_to]) unless sg_definition.reply_to?
36
37
  set_subject(params[:subject]) unless sg_definition.subject?
37
38
  set_body(params)
38
39
  add_attachments
@@ -1,3 +1,3 @@
1
1
  module SendGridMailer
2
- VERSION = "2.3.0"
2
+ VERSION = "2.4.0"
3
3
  end
@@ -48,6 +48,15 @@ class TestMailer < ApplicationMailer
48
48
  mail(template_id: "XXX")
49
49
  end
50
50
 
51
+ def reply_to_email
52
+ set_reply_to("reply-to@platan.us")
53
+ mail(body: "X")
54
+ end
55
+
56
+ def reply_to_params_email
57
+ mail(reply_to: "reply-to@platan.us", body: "X")
58
+ end
59
+
51
60
  def subject_email
52
61
  set_subject("My Subject")
53
62
  mail(body: "X")
File without changes