mail_plugger 1.0.0.rc1 → 1.2.0
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/CHANGELOG.md +54 -2
- data/README.md +40 -22
- data/lib/fake_plugger/delivery_method.rb +164 -0
- data/lib/fake_plugger/railtie.rb +14 -0
- data/lib/mail_plugger.rb +11 -2
- data/lib/mail_plugger/delivery_method.rb +2 -2
- data/lib/mail_plugger/version.rb +1 -1
- metadata +17 -48
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -22
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -16
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.rubocop.yml +0 -53
- data/.travis.yml +0 -22
- data/Appraisals +0 -13
- data/CODE_OF_CONDUCT.md +0 -14
- data/CONTRIBUTING.md +0 -26
- data/Gemfile +0 -19
- data/Gemfile.lock +0 -92
- data/Rakefile +0 -11
- data/bin/console +0 -17
- data/bin/setup +0 -8
- data/docs/usage_in_ruby_on_rails.md +0 -182
- data/docs/usage_in_script_or_console.md +0 -158
- data/docs/usage_of_attachments_in_ruby_on_rails.md +0 -110
- data/docs/usage_of_aws_ses_in_ruby_on_rails.md +0 -136
- data/docs/usage_of_delivery_method.md +0 -104
- data/docs/usage_of_mailgun_in_ruby_on_rails.md +0 -58
- data/docs/usage_of_mandrill_in_ruby_on_rails.md +0 -104
- data/docs/usage_of_more_delivery_system_in_ruby_on_rails.md +0 -332
- data/docs/usage_of_one_delivery_system_with_more_send_methods_in_ruby_on_rails.md +0 -119
- data/docs/usage_of_plug_in_method.md +0 -62
- data/docs/usage_of_postmark_in_ruby_on_rails.md +0 -59
- data/docs/usage_of_secial_options_in_ruby_on_rails.md +0 -90
- data/docs/usage_of_sendgrid_in_ruby_on_rails.md +0 -82
- data/docs/usage_of_sparkpost_in_ruby_on_rails.md +0 -142
- data/gemfiles/.bundle/config +0 -2
- data/gemfiles/mail_2.6.gemfile +0 -15
- data/gemfiles/mail_2.6.gemfile.lock +0 -95
- data/gemfiles/mail_2.7.0.gemfile +0 -15
- data/gemfiles/mail_2.7.0.gemfile.lock +0 -93
- data/gemfiles/mail_2.7.gemfile +0 -15
- data/gemfiles/mail_2.7.gemfile.lock +0 -93
- data/images/mail_plugger.png +0 -0
- data/mail_plugger.gemspec +0 -40
@@ -1,58 +0,0 @@
|
|
1
|
-
# How to use Mailgun with MailPlugger in Ruby on Rails
|
2
|
-
|
3
|
-
**Please note that these examples were not tested, but I believe it should work.**
|
4
|
-
|
5
|
-
Let's use mailer method which was defined [here](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_in_ruby_on_rails.md).
|
6
|
-
|
7
|
-
Add `mailgun-ruby` to the `Gemfile`.
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'mailgun-ruby'
|
11
|
-
```
|
12
|
-
|
13
|
-
Then run `bundle install` command to deploy the gem.
|
14
|
-
|
15
|
-
Change the API and `MailPlugger.plug_in` method in `config/initializers/mail_plugger.rb`.
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
class MailgunApiClient
|
19
|
-
def initialize(options = {})
|
20
|
-
@settings = { api_key: ENV['MAILGUN_API_KEY'] }
|
21
|
-
@options = options
|
22
|
-
end
|
23
|
-
|
24
|
-
def deliver
|
25
|
-
Mailgun::Client.new(@settings[:api_key]).send_message('sending_domain.com', generate_mail_hash)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def generate_mail_hash
|
31
|
-
{
|
32
|
-
from: @options[:from].first,
|
33
|
-
to: @options[:to].join(','),
|
34
|
-
subject: @options[:subject],
|
35
|
-
text: @options[:text_part],
|
36
|
-
html: @options[:html_part]
|
37
|
-
}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
MailPlugger.plug_in('mailgun') do |api|
|
42
|
-
api.delivery_options = %i[from to subject text_part html_part]
|
43
|
-
api.delivery_settings = { return_response: true }
|
44
|
-
api.client = MailgunApiClient
|
45
|
-
end
|
46
|
-
```
|
47
|
-
|
48
|
-
Then modify the mailer method a little bit.
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
class TestMailer < ApplicationMailer
|
52
|
-
default from: 'from@example.com'
|
53
|
-
|
54
|
-
def send_test
|
55
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'mailgun'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
```
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# How to use Mandrill with MailPlugger in Ruby on Rails
|
2
|
-
|
3
|
-
**Please note that these examples were not tested, but I believe it should work.**
|
4
|
-
|
5
|
-
Let's use mailer method which was defined [here](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_in_ruby_on_rails.md).
|
6
|
-
|
7
|
-
Add `mandrill-api-json` to the `Gemfile`.
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'mandrill-api-json'
|
11
|
-
```
|
12
|
-
|
13
|
-
Then run `bundle install` command to deploy the gem.
|
14
|
-
|
15
|
-
## Send
|
16
|
-
|
17
|
-
Change the API and `MailPlugger.plug_in` method in `config/initializers/mail_plugger.rb`.
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
class MandrillApiClient
|
21
|
-
def initialize(options = {})
|
22
|
-
@settings = { api_key: ENV['MANDRILL_API_KEY'] }
|
23
|
-
@options = options
|
24
|
-
end
|
25
|
-
|
26
|
-
def deliver
|
27
|
-
Mandrill::API.new(@settings[:api_key]).messages.send(generate_mail_hash)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def generate_mail_hash
|
33
|
-
{
|
34
|
-
from_email: @options[:from].first,
|
35
|
-
to: generate_recipients,
|
36
|
-
subject: @options[:subject],
|
37
|
-
text: @options[:text_part],
|
38
|
-
html: @options[:html_part],
|
39
|
-
tags: [@options[:tag]]
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def generate_recipients
|
44
|
-
@options[:to].map do |to|
|
45
|
-
{
|
46
|
-
email: to
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
MailPlugger.plug_in('mandrill') do |api|
|
53
|
-
api.delivery_options = %i[from to subject text_part html_part tag]
|
54
|
-
api.delivery_settings = { return_response: true }
|
55
|
-
api.client = MandrillApiClient
|
56
|
-
end
|
57
|
-
```
|
58
|
-
|
59
|
-
Then modify the mailer method a little bit.
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
class TestMailer < ApplicationMailer
|
63
|
-
default from: 'from@example.com'
|
64
|
-
|
65
|
-
def send_test
|
66
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'mandrill', tag: 'send_test'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
```
|
70
|
-
|
71
|
-
## Send Raw
|
72
|
-
|
73
|
-
Change the API and `MailPlugger.plug_in` method in `config/initializers/mail_plugger.rb`.
|
74
|
-
|
75
|
-
```ruby
|
76
|
-
class MandrillApiClient
|
77
|
-
def initialize(options = {})
|
78
|
-
@settings = { api_key: ENV['MANDRILL_API_KEY'] }
|
79
|
-
@options = options
|
80
|
-
end
|
81
|
-
|
82
|
-
def deliver
|
83
|
-
Mandrill::API.new(@settings[:api_key]).messages.send_raw(@options[:message_obj].to_s)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
MailPlugger.plug_in('mandrill') do |api|
|
88
|
-
api.delivery_options = %i[message_obj]
|
89
|
-
api.delivery_settings = { return_response: true }
|
90
|
-
api.client = MandrillApiClient
|
91
|
-
end
|
92
|
-
```
|
93
|
-
|
94
|
-
Then modify the mailer method a little bit.
|
95
|
-
|
96
|
-
```ruby
|
97
|
-
class TestMailer < ApplicationMailer
|
98
|
-
default from: 'from@example.com'
|
99
|
-
|
100
|
-
def send_test
|
101
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'mandrill'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
```
|
@@ -1,332 +0,0 @@
|
|
1
|
-
# How to use more delivey systems in Ruby on Rails
|
2
|
-
|
3
|
-
Let's modify the configuration which was defined [here](https://github.com/norbertszivos/mail_plugger/blob/main/docs/usage_in_ruby_on_rails.md).
|
4
|
-
|
5
|
-
Add a new API Class in `config/initializers/mail_plugger.rb` (you can define it in another place just now it is esasier to do this).
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
# NOTE: This is just an example for testing...
|
9
|
-
class TestApiClientClass
|
10
|
-
def initialize(options = {})
|
11
|
-
@settings = { api_key: '12345' }
|
12
|
-
@options = options
|
13
|
-
end
|
14
|
-
|
15
|
-
def deliver
|
16
|
-
# e.g. API.new(@settings).client.post(generate_mail_hash)
|
17
|
-
puts " >>> settings: #{@settings.inspect}"
|
18
|
-
puts " >>> options: #{@options.inspect}"
|
19
|
-
puts " >>> generate_mail_hash: #{generate_mail_hash.inspect}"
|
20
|
-
{ response: 'Message sent via API' }
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def generate_mail_hash
|
26
|
-
{
|
27
|
-
to: generate_recipients,
|
28
|
-
from: {
|
29
|
-
email: @options[:from].first
|
30
|
-
},
|
31
|
-
subject: @options[:subject],
|
32
|
-
content: [
|
33
|
-
{
|
34
|
-
type: 'text/plain',
|
35
|
-
value: @options[:text_part]
|
36
|
-
},
|
37
|
-
{
|
38
|
-
type: 'text/html; charset=UTF-8',
|
39
|
-
value: @options[:html_part]
|
40
|
-
}
|
41
|
-
]
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def generate_recipients
|
46
|
-
@options[:to].map do |to|
|
47
|
-
{
|
48
|
-
email: to
|
49
|
-
}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class TestApi2ClientClass
|
55
|
-
def initialize(options = {})
|
56
|
-
@settings = { api_key: '54321' }
|
57
|
-
@options = options
|
58
|
-
end
|
59
|
-
|
60
|
-
def deliver
|
61
|
-
# e.g. API.new(@settings).client.post(generate_mail_hash)
|
62
|
-
puts " >>> settings: #{@settings.inspect}"
|
63
|
-
puts " >>> options: #{@options.inspect}"
|
64
|
-
puts " >>> generate_mail_hash: #{generate_mail_hash.inspect}"
|
65
|
-
{ response: 'Message sent via API2' }
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def generate_mail_hash
|
71
|
-
{
|
72
|
-
to: generate_recipients,
|
73
|
-
from: {
|
74
|
-
email: @options[:from].first
|
75
|
-
},
|
76
|
-
subject: @options[:subject],
|
77
|
-
content: [
|
78
|
-
{
|
79
|
-
type: 'text/plain',
|
80
|
-
value: @options[:text_part]
|
81
|
-
},
|
82
|
-
{
|
83
|
-
type: 'text/html; charset=UTF-8',
|
84
|
-
value: @options[:html_part]
|
85
|
-
}
|
86
|
-
]
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def generate_recipients
|
91
|
-
@options[:to].map do |to|
|
92
|
-
{
|
93
|
-
email: to
|
94
|
-
}
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
MailPlugger.plug_in('test_api_client') do |api|
|
100
|
-
api.delivery_options = %i[from to subject text_part html_part]
|
101
|
-
api.delivery_settings = { return_response: true }
|
102
|
-
api.client = TestApiClientClass
|
103
|
-
end
|
104
|
-
|
105
|
-
MailPlugger.plug_in('test_api2_client') do |api|
|
106
|
-
api.delivery_options = %i[from to subject text_part html_part]
|
107
|
-
api.delivery_settings = { return_response: true }
|
108
|
-
api.client = TestApi2ClientClass
|
109
|
-
end
|
110
|
-
```
|
111
|
-
|
112
|
-
Then change `app/mailers/test_mailer.rb` file.
|
113
|
-
|
114
|
-
```ruby
|
115
|
-
class TestMailer < ApplicationMailer
|
116
|
-
default from: 'from@example.com'
|
117
|
-
|
118
|
-
def send_test
|
119
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'test_api_client'
|
120
|
-
end
|
121
|
-
|
122
|
-
def send_test2
|
123
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'test_api2_client'
|
124
|
-
end
|
125
|
-
end
|
126
|
-
```
|
127
|
-
|
128
|
-
Then we should add views of the second mailer method, so create `app/views/test_mailer/send_test2.html.erb`
|
129
|
-
|
130
|
-
```erb
|
131
|
-
<p>Test email body</p>
|
132
|
-
```
|
133
|
-
|
134
|
-
and `app/views/test_mailer/send_test2.text.erb`.
|
135
|
-
|
136
|
-
```erb
|
137
|
-
Test email body
|
138
|
-
```
|
139
|
-
|
140
|
-
In the `rails console` we can try it out.
|
141
|
-
|
142
|
-
```ruby
|
143
|
-
TestMailer.send_test.deliver_now!
|
144
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
145
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
146
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
147
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
148
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
149
|
-
# >>> settings: {:api_key=>"12345"}
|
150
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
151
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
152
|
-
#=> {:response=>"Message sent via API"}
|
153
|
-
|
154
|
-
TestMailer.send_test2.deliver_now!
|
155
|
-
# Rendering test_mailer/send_test2.html.erb within layouts/mailer
|
156
|
-
# Rendered test_mailer/send_test2.html.erb within layouts/mailer (2.6ms)
|
157
|
-
# Rendering test_mailer/send_test2.text.erb within layouts/mailer
|
158
|
-
# Rendered test_mailer/send_test2.text.erb within layouts/mailer (0.4ms)
|
159
|
-
#TestMailer#send_test2: processed outbound mail in 33.9ms
|
160
|
-
# >>> settings: {:api_key=>"54321"}
|
161
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
162
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
163
|
-
#=> {:response=>"Message sent via API2"}
|
164
|
-
```
|
165
|
-
|
166
|
-
In the `app/mailers/test_mailer.rb` file we can use the Rails default option as well to define `delivery_system`.
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
class TestMailer < ApplicationMailer
|
170
|
-
default from: 'from@example.com', delivery_system: 'test_api_client'
|
171
|
-
|
172
|
-
def send_test
|
173
|
-
mail subject: 'Test email', to: 'to@example.com'
|
174
|
-
end
|
175
|
-
|
176
|
-
def send_test2
|
177
|
-
mail subject: 'Test email', to: 'to@example.com'
|
178
|
-
end
|
179
|
-
end
|
180
|
-
```
|
181
|
-
|
182
|
-
In the `rails console` we can try it out.
|
183
|
-
|
184
|
-
```ruby
|
185
|
-
TestMailer.send_test.deliver_now!
|
186
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
187
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
188
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
189
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
190
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
191
|
-
# >>> settings: {:api_key=>"12345"}
|
192
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
193
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
194
|
-
#=> {:response=>"Message sent via API"}
|
195
|
-
|
196
|
-
TestMailer.send_test2.deliver_now!
|
197
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
198
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
199
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
200
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
201
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
202
|
-
# >>> settings: {:api_key=>"12345"}
|
203
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
204
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
205
|
-
#=> {:response=>"Message sent via API"}
|
206
|
-
```
|
207
|
-
|
208
|
-
Or we can use default, but override it in the method.
|
209
|
-
|
210
|
-
```ruby
|
211
|
-
class TestMailer < ApplicationMailer
|
212
|
-
default from: 'from@example.com', delivery_system: 'test_api_client'
|
213
|
-
|
214
|
-
def send_test
|
215
|
-
mail subject: 'Test email', to: 'to@example.com'
|
216
|
-
end
|
217
|
-
|
218
|
-
def send_test2
|
219
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'test_api2_client'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
```
|
223
|
-
|
224
|
-
In the `rails console` we can try it out.
|
225
|
-
|
226
|
-
```ruby
|
227
|
-
TestMailer.send_test.deliver_now!
|
228
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
229
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
230
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
231
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
232
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
233
|
-
# >>> settings: {:api_key=>"12345"}
|
234
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
235
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
236
|
-
#=> {:response=>"Message sent via API"}
|
237
|
-
|
238
|
-
TestMailer.send_test2.deliver_now!
|
239
|
-
# Rendering test_mailer/send_test2.html.erb within layouts/mailer
|
240
|
-
# Rendered test_mailer/send_test2.html.erb within layouts/mailer (2.6ms)
|
241
|
-
# Rendering test_mailer/send_test2.text.erb within layouts/mailer
|
242
|
-
# Rendered test_mailer/send_test2.text.erb within layouts/mailer (0.4ms)
|
243
|
-
#TestMailer#send_test2: processed outbound mail in 33.9ms
|
244
|
-
# >>> settings: {:api_key=>"54321"}
|
245
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
246
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
247
|
-
#=> {:response=>"Message sent via API2"}
|
248
|
-
```
|
249
|
-
|
250
|
-
Or if we are not define any `delivey_system` then it will use the first defined one with `MailPlugger.plug_in` method.
|
251
|
-
|
252
|
-
```ruby
|
253
|
-
class TestMailer < ApplicationMailer
|
254
|
-
default from: 'from@example.com'
|
255
|
-
|
256
|
-
def send_test
|
257
|
-
mail subject: 'Test email', to: 'to@example.com'
|
258
|
-
end
|
259
|
-
|
260
|
-
def send_test2
|
261
|
-
mail subject: 'Test email', to: 'to@example.com'
|
262
|
-
end
|
263
|
-
end
|
264
|
-
```
|
265
|
-
|
266
|
-
In the `rails console` we can try it out.
|
267
|
-
|
268
|
-
```ruby
|
269
|
-
TestMailer.send_test.deliver_now!
|
270
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
271
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
272
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
273
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
274
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
275
|
-
# >>> settings: {:api_key=>"12345"}
|
276
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
277
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
278
|
-
#=> {:response=>"Message sent via API"}
|
279
|
-
|
280
|
-
TestMailer.send_test2.deliver_now!
|
281
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
282
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
283
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
284
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
285
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
286
|
-
# >>> settings: {:api_key=>"12345"}
|
287
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
288
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
289
|
-
#=> {:response=>"Message sent via API"}
|
290
|
-
```
|
291
|
-
|
292
|
-
Or we can just define `delivery_system` where we would like to use the other one.
|
293
|
-
|
294
|
-
```ruby
|
295
|
-
class TestMailer < ApplicationMailer
|
296
|
-
default from: 'from@example.com'
|
297
|
-
|
298
|
-
def send_test
|
299
|
-
mail subject: 'Test email', to: 'to@example.com'
|
300
|
-
end
|
301
|
-
|
302
|
-
def send_test2
|
303
|
-
mail subject: 'Test email', to: 'to@example.com', delivery_system: 'test_api2_client'
|
304
|
-
end
|
305
|
-
end
|
306
|
-
```
|
307
|
-
|
308
|
-
In the `rails console` we can try it out.
|
309
|
-
|
310
|
-
```ruby
|
311
|
-
TestMailer.send_test.deliver_now!
|
312
|
-
# Rendering test_mailer/send_test.html.erb within layouts/mailer
|
313
|
-
# Rendered test_mailer/send_test.html.erb within layouts/mailer (1.0ms)
|
314
|
-
# Rendering test_mailer/send_test.text.erb within layouts/mailer
|
315
|
-
# Rendered test_mailer/send_test.text.erb within layouts/mailer (0.3ms)
|
316
|
-
#TestMailer#send_test: processed outbound mail in 46.1ms
|
317
|
-
# >>> settings: {:api_key=>"12345"}
|
318
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
319
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
320
|
-
#=> {:response=>"Message sent via API"}
|
321
|
-
|
322
|
-
TestMailer.send_test2.deliver_now!
|
323
|
-
# Rendering test_mailer/send_test2.html.erb within layouts/mailer
|
324
|
-
# Rendered test_mailer/send_test2.html.erb within layouts/mailer (2.6ms)
|
325
|
-
# Rendering test_mailer/send_test2.text.erb within layouts/mailer
|
326
|
-
# Rendered test_mailer/send_test2.text.erb within layouts/mailer (0.4ms)
|
327
|
-
#TestMailer#send_test2: processed outbound mail in 33.9ms
|
328
|
-
# >>> settings: {:api_key=>"54321"}
|
329
|
-
# >>> options: {"from"=>["from@example.com"], "to"=>["to@example.com"], "subject"=>"Test email", "text_part"=>"Test email body\n\n", "html_part"=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}
|
330
|
-
# >>> generate_mail_hash: {:to=>[{:email=>"to@example.com"}], :from=>{:email=>"from@example.com"}, :subject=>"Test email", :content=>[{:type=>"text/plain", :value=>"Test email body\n\n"}, {:type=>"text/html; charset=UTF-8", :value=>"<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <style>\n /* Email styles need to be inline */\n </style>\n </head>\n\n <body>\n <p>Test email body</p>\n\n </body>\n</html>\n"}]}
|
331
|
-
#=> {:response=>"Message sent via API2"}
|
332
|
-
```
|