Skip to content

Commit e60ef7b

Browse files
committed
Add reply_to
1 parent cecd916 commit e60ef7b

File tree

8 files changed

+22
-1
lines changed

8 files changed

+22
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mail = Mailtrap::Mail::Base.new(
5252
to: [
5353
{ email: '[email protected]' }
5454
],
55+
reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
5556
subject: 'You are awesome!',
5657
text: "Congrats for sending test email with Mailtrap!"
5758
)

examples/action_mailer.rb

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# To add `category` and `custom_variables`, add them to the mail generation:
1919
mail(
2020
21+
reply_to: 'Mailtrap Reply-To <[email protected]>',
2122
subject: 'You are awesome!',
2223
category: 'Test category',
2324
custom_variables: { test_variable: 'abc' }

examples/email_template.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
to: [
77
{ email: '[email protected]' }
88
],
9+
reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
910
template_uuid: '2f45b0aa-bbed-432f-95e4-e145e1965ba2',
1011
template_variables: {
1112
'user_name' => 'John Doe'

examples/full.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
to: [
77
{ email: '[email protected]', name: 'Your name' }
88
],
9+
reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
910
cc: [
1011
{ email: '[email protected]', name: 'Copy To' }
1112
],

lib/mailtrap/mail/base.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
module Mailtrap
66
module Mail
77
class Base
8-
attr_accessor :from, :to, :cc, :bcc, :headers, :custom_variables, :subject, :text, :html, :category
8+
attr_accessor :from, :to, :reply_to, :cc, :bcc, :headers, :custom_variables, :subject, :text, :html, :category
99
attr_reader :attachments
1010

1111
def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
1212
from: nil,
1313
to: [],
14+
reply_to: nil,
1415
cc: [],
1516
bcc: [],
1617
subject: nil,
@@ -23,6 +24,7 @@ def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
2324
)
2425
@from = from
2526
@to = to
27+
@reply_to = reply_to
2628
@cc = cc
2729
@bcc = bcc
2830
@subject = subject
@@ -38,6 +40,7 @@ def as_json # rubocop:disable Metrics/MethodLength
3840
{
3941
'from' => from,
4042
'to' => to,
43+
'reply_to' => reply_to,
4144
'cc' => cc,
4245
'bcc' => bcc,
4346
'subject' => subject,

lib/mailtrap/mail/from_template.rb

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FromTemplate < Base
88
def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
99
from: nil,
1010
to: [],
11+
reply_to: nil,
1112
cc: [],
1213
bcc: [],
1314
attachments: [],
@@ -19,6 +20,7 @@ def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
1920
super(
2021
from: from,
2122
to: to,
23+
reply_to: reply_to,
2224
cc: cc,
2325
bcc: bcc,
2426
attachments: attachments,

spec/mailtrap/mail/base_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
described_class.new(
99
from: from,
1010
to: to,
11+
reply_to: reply_to,
1112
cc: cc,
1213
bcc: bcc,
1314
subject: mail_subject,
@@ -22,6 +23,7 @@
2223

2324
let(:from) { nil }
2425
let(:to) { [] }
26+
let(:reply_to) { nil }
2527
let(:cc) { [] }
2628
let(:bcc) { [] }
2729
let(:mail_subject) { nil }
@@ -80,6 +82,7 @@
8082
end
8183

8284
context 'when all values set' do
85+
let(:reply_to) { { email: '[email protected]' } }
8386
let(:cc) { [{ email: '[email protected]' }] }
8487
let(:bcc) { [{ email: '[email protected]' }] }
8588
let(:html) { '<div>Test HTML</div>' }
@@ -91,6 +94,7 @@
9194
{
9295
'from' => { email: '[email protected]', name: 'Mailtrap User' },
9396
'to' => [{ email: '[email protected]' }, { email: '[email protected]', name: 'To Two' }],
97+
'reply_to' => { email: '[email protected]' },
9498
'cc' => [{ email: '[email protected]' }],
9599
'bcc' => [{ email: '[email protected]' }],
96100
'subject' => 'This is subject',
@@ -114,6 +118,7 @@
114118

115119
let(:from) { { email: '[email protected]', name: 'Mailtrap User' } }
116120
let(:to) { [{ email: '[email protected]' }, { email: '[email protected]', name: 'To Two' }] }
121+
let(:reply_to) { { email: '[email protected]', name: 'Reply To' } }
117122
let(:mail_subject) { 'This is subject' }
118123
let(:text) { 'This is text' }
119124
let(:cc) { [{ email: '[email protected]' }] }
@@ -126,6 +131,7 @@
126131
'{' \
127132
'"from":{"email":"[email protected]","name":"Mailtrap User"},' \
128133
'"to":[{"email":"[email protected]"},{"email":"[email protected]","name":"To Two"}],' \
134+
'"reply_to":{"email":"[email protected]","name":"Reply To"},' \
129135
'"cc":[{"email":"[email protected]"}],' \
130136
'"bcc":[{"email":"[email protected]"}],' \
131137
'"subject":"This is subject",' \

spec/mailtrap/mail/from_template_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
described_class.new(
99
from: from,
1010
to: to,
11+
reply_to: reply_to,
1112
cc: cc,
1213
bcc: bcc,
1314
attachments: attachments,
@@ -20,6 +21,7 @@
2021

2122
let(:from) { nil }
2223
let(:to) { [] }
24+
let(:reply_to) { nil }
2325
let(:cc) { [] }
2426
let(:bcc) { [] }
2527
let(:attachments) { [] }
@@ -43,6 +45,7 @@
4345
context 'when all values set' do
4446
let(:from) { { email: '[email protected]', name: 'Mailtrap User' } }
4547
let(:to) { [{ email: '[email protected]' }, { email: '[email protected]', name: 'To Two' }] }
48+
let(:reply_to) { { email: '[email protected]' } }
4649
let(:cc) { [{ email: '[email protected]' }] }
4750
let(:bcc) { [{ email: '[email protected]' }] }
4851
let(:html) { '<div>Test HTML</div>' }
@@ -64,6 +67,7 @@
6467
{
6568
'from' => { email: '[email protected]', name: 'Mailtrap User' },
6669
'to' => [{ email: '[email protected]' }, { email: '[email protected]', name: 'To Two' }],
70+
'reply_to' => { email: '[email protected]' },
6771
'cc' => [{ email: '[email protected]' }],
6872
'bcc' => [{ email: '[email protected]' }],
6973
'headers' => { 'Category-Header' => 'some_category' },
@@ -113,6 +117,7 @@
113117

114118
let(:from) { { email: '[email protected]', name: 'Mailtrap User' } }
115119
let(:to) { [{ email: '[email protected]' }, { email: '[email protected]', name: 'To Two' }] }
120+
let(:reply_to) { { email: '[email protected]', name: 'Reply To' } }
116121
let(:cc) { [{ email: '[email protected]' }] }
117122
let(:bcc) { [{ email: '[email protected]' }] }
118123
let(:attachments) { [{ content: StringIO.new('hello world'), filename: 'attachment.txt' }] }
@@ -123,6 +128,7 @@
123128
'{' \
124129
'"from":{"email":"[email protected]","name":"Mailtrap User"},' \
125130
'"to":[{"email":"[email protected]"},{"email":"[email protected]","name":"To Two"}],' \
131+
'"reply_to":{"email":"[email protected]","name":"Reply To"},' \
126132
'"cc":[{"email":"[email protected]"}],' \
127133
'"bcc":[{"email":"[email protected]"}],' \
128134
'"attachments":[{"content":"aGVsbG8gd29ybGQ=","filename":"attachment.txt"}],' \

0 commit comments

Comments
 (0)