mail_plugger 1.1.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -3
- data/README.md +34 -30
- data/lib/fake_plugger/delivery_method.rb +149 -17
- data/lib/mail_plugger/delivery_method.rb +56 -2
- data/lib/mail_plugger/mail_helper.rb +75 -14
- data/lib/mail_plugger/version.rb +1 -1
- data/lib/mail_plugger.rb +28 -6
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 174f3fa6b0708e5e3635df906ef07df145dbfecade90452bae98d2bfef912f5a
|
4
|
+
data.tar.gz: 58c9aa8b5a2dc5d6552a02d79775d45bfbea6bb770fa4943b97986d4c58ad485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de355d0eff072fcd5ac56b99d258143a7d52eb7edfd23851335c8089ffab8cde18fb86fb6c952828b8529f573778216c10118043322df703311b491605c0779
|
7
|
+
data.tar.gz: 46c0e544614420ade838a70b01031fbd2cf3698c98c7666869638bbfb42622dbf9ea47261a013bbb461e3ba4bffc5497ece8bc222da55bd65479bede4d127edc
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,58 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## 1.5.0 (2021-12-31)
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
|
7
|
+
* Add Ruby 3.1 support.
|
8
|
+
* Drop Ruby 2.5 support.
|
9
|
+
* Require MFA on RubyGems.
|
10
|
+
* Update bundler and gems.
|
11
|
+
* Fix typo in the README.md.
|
12
|
+
* Replace Travis with GitHub Actions.
|
13
|
+
|
14
|
+
|
15
|
+
## 1.4.0 (2021-06-08)
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
* Add SMTP support. With this modifications we can use SMTP and API delivery methods as well.
|
20
|
+
|
21
|
+
### Changes
|
22
|
+
|
23
|
+
* Update bundler and gems.
|
24
|
+
|
25
|
+
|
26
|
+
## 1.3.0 (2021-04-14)
|
27
|
+
|
28
|
+
### New features
|
29
|
+
|
30
|
+
* Add MailGrabber to FakePlugger. Now we can use FakePlugger and MailGrabber in same time.
|
31
|
+
|
32
|
+
### Changes
|
33
|
+
|
34
|
+
* Remove unnecessary double quotes from `show_debug_info` method in `FakePlugger::DeliveryMethod` and fix documentations.
|
35
|
+
* Update bundler and gems.
|
36
|
+
* Update bug_report.md.
|
37
|
+
|
38
|
+
|
39
|
+
## 1.2.0 (2021-03-18)
|
40
|
+
|
41
|
+
### New organization
|
42
|
+
|
43
|
+
* Move mail_plugger repository into MailToolbox organization.
|
44
|
+
|
45
|
+
### Changes
|
46
|
+
|
47
|
+
* Update gems.
|
48
|
+
* Fix some documentation issues.
|
49
|
+
|
3
50
|
|
4
51
|
## 1.1.1 (2021-01-21)
|
5
52
|
|
6
53
|
### Changes
|
7
54
|
|
8
|
-
* Change FakePlugger::DeliveryMethod to returns with the extracted delivery data instead of the message object.
|
55
|
+
* Change `FakePlugger::DeliveryMethod` to returns with the extracted delivery data instead of the message object.
|
9
56
|
* Update code documentations.
|
10
57
|
* Add missing FakePlugger description in the README.md.
|
11
58
|
|
@@ -51,9 +98,9 @@
|
|
51
98
|
* Check hash keys in `MailPlugger::MailHelper.delivery_system` method, so now if we are add wrong `delivey_system` then we are getting a meaningful error message.
|
52
99
|
* Change `MailPlugger::MailHelper.extract_attachments` method. If an attachment is inline then the hash contains the `filename` and `cid` as well.
|
53
100
|
* Add/Change tests.
|
54
|
-
* Change `MailPlugger::MailHelper.delivery_option` that returns with indifferent hash
|
101
|
+
* Change `MailPlugger::MailHelper.delivery_option` that returns with indifferent hash.
|
55
102
|
|
56
103
|
|
57
104
|
## 1.0.0.beta1 (2021-01-02)
|
58
105
|
|
59
|
-
* Implement MailPlugger methods and functionality. See [README.md](https://github.com/
|
106
|
+
* Implement MailPlugger methods and functionality. See [README.md](https://github.com/MailToolbox/mail_plugger/blob/main/README.md)
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# M<img src="https://raw.githubusercontent.com/
|
1
|
+
# M<img src="https://raw.githubusercontent.com/MailToolbox/mail_plugger/main/images/mail_plugger800x500.png" height="22" />ilPlugger
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mail_plugger.svg)](https://badge.fury.io/rb/mail_plugger)
|
4
|
-
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE.txt)
|
4
|
+
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen)](https://github.com/MailToolbox/mail_plugger/blob/main/LICENSE.txt)
|
5
5
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
|
6
|
-
[![
|
7
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
8
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/
|
6
|
+
[![MailPlugger CI](https://github.com/MailToolbox/mail_plugger/actions/workflows/mail_plugger_ci.yml/badge.svg)](https://github.com/MailToolbox/mail_plugger/actions/workflows/mail_plugger_ci.yml)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/137881380fc475b4a836/maintainability)](https://codeclimate.com/github/MailToolbox/mail_plugger/maintainability)
|
8
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/137881380fc475b4a836/test_coverage)](https://codeclimate.com/github/MailToolbox/mail_plugger/test_coverage)
|
9
9
|
|
10
|
-
**MailPlugger** helps you to use different mail providers' **API**. You can use any APIs which one would like to use. It allows you to send different emails with different APIs. Also it can help to move between providers, load
|
10
|
+
**MailPlugger** helps you to use different mail providers' **SMTP** and **API**. You can use any SMTPs and APIs which one would like to use. It allows you to send different emails with different SMTPs and APIs. Also it can help to move between providers, load balancing or cost management.
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -27,30 +27,34 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
- [How to use MailPlugger.plug_in method](https://github.com/
|
31
|
-
- [How to use MailPlugger::DeliveryMethod class](https://github.com/
|
32
|
-
- [How to use MailPlugger in a Ruby script or IRB console](https://github.com/
|
33
|
-
- [How to use MailPlugger in Ruby on Rails](https://github.com/
|
34
|
-
- [How to
|
35
|
-
- [How to
|
36
|
-
- [How to
|
37
|
-
- [How to use
|
38
|
-
- [How to use
|
39
|
-
- [How to use
|
40
|
-
- [How to use
|
41
|
-
- [How to use
|
42
|
-
- [How to use
|
43
|
-
- [How to use
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
- [How to use MailPlugger.plug_in method](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_plug_in_method.md)
|
31
|
+
- [How to use MailPlugger::DeliveryMethod class](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_delivery_method.md)
|
32
|
+
- [How to use MailPlugger in a Ruby script or IRB console](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_in_script_or_console.md)
|
33
|
+
- [How to use MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_in_ruby_on_rails.md)
|
34
|
+
- [How to use more SMTP delivery systems in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_more_smtp_delivery_systems_in_ruby_on_rails.md)
|
35
|
+
- [How to combine SMTP and API delivery systems in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_smtp_and_api_delivery_systems_in_ruby_on_rails.md)
|
36
|
+
- [How to add API specific options to the mailer method in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_api_specific_options_in_ruby_on_rails.md)
|
37
|
+
- [How to use API delivery system that add attachments to the mailer method in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_api_attachments_in_ruby_on_rails.md)
|
38
|
+
- [How to use more API delivery systems in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_more_api_delivery_systems_in_ruby_on_rails.md)
|
39
|
+
- [How to use one API delivery system with more send methods in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_one_api_delivery_system_with_more_send_methods_in_ruby_on_rails.md)
|
40
|
+
- [How to use AWS SES API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_aws_ses_api_in_ruby_on_rails.md)
|
41
|
+
- [How to use SparkPost API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_sparkpost_api_in_ruby_on_rails.md)
|
42
|
+
- [How to use SendGrid API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_sendgrid_api_in_ruby_on_rails.md)
|
43
|
+
- [How to use Mandrill API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_mandrill_api_in_ruby_on_rails.md)
|
44
|
+
- [How to use Postmark API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_postmark_api_in_ruby_on_rails.md)
|
45
|
+
- [How to use Mailgun API with MailPlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_mailgun_api_in_ruby_on_rails.md)
|
46
|
+
|
47
|
+
# F<img src="https://raw.githubusercontent.com/MailToolbox/mail_plugger/main/images/fake_plugger800x500.png" height="22" />kePlugger
|
48
|
+
|
49
|
+
**FakePlugger** is a delivery method to mock **MailPlugger**. It is working similarly like **MailPlugger**, but it won't send any emails (but if we would like it is possible, just we should do manually). Also it can write out debug informations or we can manipulate the response with it. Another option that we can use **[MailGrabber](https://github.com/MailToolbox/mail_grabber)** web interface if the delivery method is `:fake_plugger`.
|
48
50
|
|
49
51
|
## Usage
|
50
52
|
|
51
|
-
- [How to use FakePlugger::DeliveryMethod class](https://github.com/
|
52
|
-
- [How to use FakePlugger in a Ruby script or IRB console](https://github.com/
|
53
|
-
- [How to use FakePlugger in Ruby on Rails](https://github.com/
|
53
|
+
- [How to use FakePlugger::DeliveryMethod class](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_fake_plugger_delivery_method.md)
|
54
|
+
- [How to use FakePlugger in a Ruby script or IRB console](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_fake_plugger_in_script_or_console.md)
|
55
|
+
- [How to use FakePlugger in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_fake_plugger_in_ruby_on_rails.md)
|
56
|
+
- [How to use FakePlugger with more delivery systems in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_fake_plugger_with_more_delivery_systems_in_ruby_on_rails.md)
|
57
|
+
- [How to use FakePlugger with MailGrabber in Ruby on Rails](https://github.com/MailToolbox/mail_plugger/blob/main/docs/usage_of_fake_plugger_with_mail_grabber_in_ruby_on_rails.md)
|
54
58
|
|
55
59
|
## Development
|
56
60
|
|
@@ -60,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
60
64
|
|
61
65
|
To release a new version:
|
62
66
|
|
63
|
-
- Update CHANGELOG.md
|
67
|
+
- Update [CHANGELOG.md](https://github.com/MailToolbox/mail_plugger/blob/main/CHANGELOG.md)
|
64
68
|
- Update the version number in `version.rb` manually or use `gem-release` gem and run `gem bump -v major|minor|patch|rc|beta`.
|
65
69
|
- Build gem with `bundle exec rake build`.
|
66
70
|
- Run `bundle install` and `bundle exec appraisal install` to update gemfiles and commit the changes.
|
@@ -68,7 +72,7 @@ To release a new version:
|
|
68
72
|
|
69
73
|
## Contributing
|
70
74
|
|
71
|
-
Bug reports and pull requests are welcome. Please read [CONTRIBUTING.md](https://github.com/
|
75
|
+
Bug reports and pull requests are welcome. Please read [CONTRIBUTING.md](https://github.com/MailToolbox/mail_plugger/blob/main/CONTRIBUTING.md) if you would like to contribute to this project.
|
72
76
|
|
73
77
|
## Inspiration
|
74
78
|
|
@@ -79,4 +83,4 @@ Bug reports and pull requests are welcome. Please read [CONTRIBUTING.md](https:/
|
|
79
83
|
|
80
84
|
## License
|
81
85
|
|
82
|
-
The gem is available as open source under the terms of the [MIT License](https://github.com/
|
86
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/MailToolbox/mail_plugger/blob/main/LICENSE.txt).
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'mail_grabber' if Gem.loaded_specs.key?('mail_grabber')
|
4
|
+
|
3
5
|
module FakePlugger
|
4
6
|
class DeliveryMethod < MailPlugger::DeliveryMethod
|
5
7
|
# Initialize FakePlugger delivery method attributes. If we are using
|
@@ -29,15 +31,27 @@ module FakePlugger
|
|
29
31
|
# @option options [String/Symbol/Array/Hash] response
|
30
32
|
# the deliver! method will return with this value or if this value is nil
|
31
33
|
# then it will return with the client object
|
34
|
+
#
|
35
|
+
# @option options [Boolean] use_mail_grabber
|
36
|
+
# if true it will store the message in a database which MailGrabber can
|
37
|
+
# read
|
32
38
|
def initialize(options = {})
|
33
39
|
super
|
34
40
|
|
35
|
-
@debug
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
@debug = options[:debug]
|
42
|
+
|
43
|
+
@raw_message = options[:raw_message]
|
44
|
+
|
45
|
+
@response = options[:response]
|
46
|
+
|
47
|
+
@use_mail_grabber = options[:use_mail_grabber]
|
39
48
|
end
|
40
49
|
|
50
|
+
# Using SMTP:
|
51
|
+
# Mock send message via SMTP protocol if the 'delivery_settings' contains a
|
52
|
+
# 'smtp_settings' key and the value is a hash with the settings.
|
53
|
+
#
|
54
|
+
# Using API:
|
41
55
|
# Mock send message with the given client if the message parameter is a
|
42
56
|
# Mail::Message object. If 'response' parameter is nil then it will extract
|
43
57
|
# those information from the Mail::Message object which was provided in the
|
@@ -46,12 +60,15 @@ module FakePlugger
|
|
46
60
|
# it won't call the 'deliver' method.
|
47
61
|
# If the 'response' parameter is a hash with 'return_delivery_data: true'
|
48
62
|
# then it will retrun with the extracted delivery data.
|
63
|
+
#
|
64
|
+
#
|
49
65
|
# If the 'response' parameter is not nil then retruns with that given data
|
50
66
|
# without call any other methods.
|
51
67
|
# Except if 'debug' is true. In this case it will call those methods which
|
52
68
|
# is calling in normal operation as well.
|
53
69
|
# If 'debug' is true then it prints out some debug informations.
|
54
70
|
# If 'raw_message' is true then it prints out raw message.
|
71
|
+
# if 'use_mail_grabber' is true then it stores the message in a database.
|
55
72
|
#
|
56
73
|
# @param [Mail::Message] message what we would like to send
|
57
74
|
#
|
@@ -59,11 +76,54 @@ module FakePlugger
|
|
59
76
|
#
|
60
77
|
# @example
|
61
78
|
#
|
79
|
+
# # Using SMTP:
|
80
|
+
#
|
81
|
+
# MailPlugger.plug_in('test_smtp_client') do |smtp|
|
82
|
+
# smtp.delivery_settings = {
|
83
|
+
# smtp_settings: {
|
84
|
+
# address: 'smtp.server.com',
|
85
|
+
# port: 587,
|
86
|
+
# domain: 'test.domain.com',
|
87
|
+
# enable_starttls_auto: true,
|
88
|
+
# user_name: 'test_user',
|
89
|
+
# password: '1234',
|
90
|
+
# authentication: :plain
|
91
|
+
# }
|
92
|
+
# }
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
96
|
+
# subject: 'Test email', body: 'Test email body')
|
97
|
+
#
|
98
|
+
# FakePlugger::DeliveryMethod.new.deliver!(message)
|
99
|
+
#
|
100
|
+
# # or
|
101
|
+
#
|
102
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
103
|
+
# subject: 'Test email', body: 'Test email body')
|
104
|
+
#
|
105
|
+
# FakePlugger::DeliveryMethod.new(
|
106
|
+
# delivery_settings: {
|
107
|
+
# smtp_settings: {
|
108
|
+
# address: 'smtp.server.com',
|
109
|
+
# port: 587,
|
110
|
+
# domain: 'test.domain.com',
|
111
|
+
# enable_starttls_auto: true,
|
112
|
+
# user_name: 'test_user',
|
113
|
+
# password: '1234',
|
114
|
+
# authentication: :plain
|
115
|
+
# }
|
116
|
+
# }
|
117
|
+
# ).deliver!(message)
|
118
|
+
#
|
119
|
+
# # Using API:
|
120
|
+
#
|
62
121
|
# MailPlugger.plug_in('test_api_client') do |api|
|
63
122
|
# api.delivery_options = %i[from to subject body]
|
64
123
|
# api.delivery_settings = {
|
65
124
|
# fake_plugger_debug: true,
|
66
125
|
# fake_plugger_raw_message: true,
|
126
|
+
# fake_plugger_use_mail_grabber: true,
|
67
127
|
# fake_plugger_response: { response: 'OK' }
|
68
128
|
# }
|
69
129
|
# api.client = DefinedApiClientClass
|
@@ -84,6 +144,7 @@ module FakePlugger
|
|
84
144
|
# client: DefinedApiClientClass,
|
85
145
|
# debug: true,
|
86
146
|
# raw_message: true,
|
147
|
+
# use_mail_grabber: true,
|
87
148
|
# response: { response: 'OK' }
|
88
149
|
# ).deliver!(message)
|
89
150
|
#
|
@@ -95,26 +156,28 @@ module FakePlugger
|
|
95
156
|
|
96
157
|
@message = message
|
97
158
|
|
98
|
-
|
99
|
-
|
159
|
+
update_settings
|
160
|
+
|
161
|
+
call_extra_options
|
100
162
|
|
101
163
|
return_with_response
|
102
164
|
end
|
103
165
|
|
104
166
|
private
|
105
167
|
|
106
|
-
#
|
107
|
-
|
108
|
-
|
109
|
-
if @
|
110
|
-
|
111
|
-
end
|
168
|
+
# Call extra options like show debug informations, show raw message,
|
169
|
+
# use mail grabber.
|
170
|
+
def call_extra_options
|
171
|
+
show_debug_info if @debug
|
172
|
+
show_raw_message if @raw_message
|
112
173
|
|
113
|
-
@
|
174
|
+
return unless Gem.loaded_specs.key?('mail_grabber') && @use_mail_grabber
|
175
|
+
|
176
|
+
MailGrabber::DeliveryMethod.new.deliver!(@message)
|
114
177
|
end
|
115
178
|
|
116
|
-
#
|
117
|
-
def
|
179
|
+
# Debug informations for API
|
180
|
+
def debug_info_for_api
|
118
181
|
puts <<~DEBUG_INFO
|
119
182
|
|
120
183
|
===================== FakePlugger::DeliveryMethod =====================
|
@@ -123,9 +186,9 @@ module FakePlugger
|
|
123
186
|
|
124
187
|
==> @client: #{@client.inspect}
|
125
188
|
|
126
|
-
==> @delivery_options: #{@delivery_options.inspect}
|
189
|
+
==> @delivery_options: #{@delivery_options.inspect}
|
127
190
|
|
128
|
-
==> @delivery_settings: #{@delivery_settings.inspect}
|
191
|
+
==> @delivery_settings: #{@delivery_settings.inspect}
|
129
192
|
|
130
193
|
==> @default_delivery_system: #{@default_delivery_system.inspect}
|
131
194
|
|
@@ -148,6 +211,62 @@ module FakePlugger
|
|
148
211
|
DEBUG_INFO
|
149
212
|
end
|
150
213
|
|
214
|
+
# Debug information for SMTP
|
215
|
+
def debug_info_for_smtp
|
216
|
+
puts <<~DEBUG_INFO
|
217
|
+
|
218
|
+
===================== FakePlugger::DeliveryMethod =====================
|
219
|
+
|
220
|
+
------------------------------ Variables ------------------------------
|
221
|
+
|
222
|
+
==> @delivery_settings: #{@delivery_settings.inspect}
|
223
|
+
|
224
|
+
==> @default_delivery_system: #{@default_delivery_system.inspect}
|
225
|
+
|
226
|
+
==> @message: #{@message.inspect}
|
227
|
+
|
228
|
+
------------------------------- Methods -------------------------------
|
229
|
+
|
230
|
+
==> delivery_system: #{delivery_system.inspect}
|
231
|
+
|
232
|
+
==> settings: #{settings.inspect}
|
233
|
+
|
234
|
+
=======================================================================
|
235
|
+
|
236
|
+
DEBUG_INFO
|
237
|
+
end
|
238
|
+
|
239
|
+
# Prepare delivery. It depends on that is SMTP or API.
|
240
|
+
def prepare_delivery
|
241
|
+
if send_via_smtp?
|
242
|
+
@message.delivery_method :smtp, settings[:smtp_settings]
|
243
|
+
@message
|
244
|
+
else
|
245
|
+
client.new(delivery_data)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Check that it should retrun with the delivery data.
|
250
|
+
def return_delivery_data?
|
251
|
+
!send_via_smtp? &&
|
252
|
+
@response.is_a?(Hash) &&
|
253
|
+
@response[:return_delivery_data]
|
254
|
+
end
|
255
|
+
|
256
|
+
# Return with a response which depends on the conditions.
|
257
|
+
def return_with_response
|
258
|
+
return prepare_delivery if @response.nil?
|
259
|
+
|
260
|
+
return delivery_data if return_delivery_data?
|
261
|
+
|
262
|
+
@response
|
263
|
+
end
|
264
|
+
|
265
|
+
# Show debug informations from variables and methods.
|
266
|
+
def show_debug_info
|
267
|
+
send_via_smtp? ? debug_info_for_smtp : debug_info_for_api
|
268
|
+
end
|
269
|
+
|
151
270
|
# Show raw message for debug purpose.
|
152
271
|
def show_raw_message
|
153
272
|
puts <<~RAW_MESSAGE
|
@@ -160,5 +279,18 @@ module FakePlugger
|
|
160
279
|
|
161
280
|
RAW_MESSAGE
|
162
281
|
end
|
282
|
+
|
283
|
+
# Extract settings values and update attributes.
|
284
|
+
def update_settings
|
285
|
+
# rubocop:disable Naming/MemoizedInstanceVariableName
|
286
|
+
@debug ||= settings[:fake_plugger_debug] || false
|
287
|
+
|
288
|
+
@raw_message ||= settings[:fake_plugger_raw_message] || false
|
289
|
+
|
290
|
+
@response ||= settings[:fake_plugger_response]
|
291
|
+
|
292
|
+
@use_mail_grabber ||= settings[:fake_plugger_use_mail_grabber] || false
|
293
|
+
# rubocop:enable Naming/MemoizedInstanceVariableName
|
294
|
+
end
|
163
295
|
end
|
164
296
|
end
|
@@ -30,12 +30,19 @@ module MailPlugger
|
|
30
30
|
@delivery_settings = options[:delivery_settings] ||
|
31
31
|
MailPlugger.delivery_settings
|
32
32
|
|
33
|
+
@delivery_systems = MailPlugger.delivery_systems
|
34
|
+
|
33
35
|
@default_delivery_system = options[:default_delivery_system] ||
|
34
36
|
default_delivery_system_get
|
35
37
|
|
36
38
|
@message = nil
|
37
39
|
end
|
38
40
|
|
41
|
+
# Using SMTP:
|
42
|
+
# Send message via SMTP protocol if the 'delivery_settings' contains a
|
43
|
+
# 'smtp_settings' key and the value is a hash with the settings.
|
44
|
+
#
|
45
|
+
# Using API:
|
39
46
|
# Send message with the given client if the message parameter is a
|
40
47
|
# Mail::Message object. Before doing that extract those information from the
|
41
48
|
# Mail::Message object which was provided in the 'delivery_options'. After
|
@@ -44,10 +51,52 @@ module MailPlugger
|
|
44
51
|
#
|
45
52
|
# @param [Mail::Message] message what we would like to send
|
46
53
|
#
|
47
|
-
# @return [Mail::Message/Hash]
|
54
|
+
# @return [Mail::Message/Hash] depends on delivery_settings and method calls
|
48
55
|
#
|
49
56
|
# @example
|
50
57
|
#
|
58
|
+
# # Using SMTP:
|
59
|
+
#
|
60
|
+
# MailPlugger.plug_in('test_smtp_client') do |smtp|
|
61
|
+
# smtp.delivery_settings = {
|
62
|
+
# smtp_settings: {
|
63
|
+
# address: 'smtp.server.com',
|
64
|
+
# port: 587,
|
65
|
+
# domain: 'test.domain.com',
|
66
|
+
# enable_starttls_auto: true,
|
67
|
+
# user_name: 'test_user',
|
68
|
+
# password: '1234',
|
69
|
+
# authentication: :plain
|
70
|
+
# }
|
71
|
+
# }
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
75
|
+
# subject: 'Test email', body: 'Test email body')
|
76
|
+
#
|
77
|
+
# MailPlugger::DeliveryMethod.new.deliver!(message)
|
78
|
+
#
|
79
|
+
# # or
|
80
|
+
#
|
81
|
+
# message = Mail.new(from: 'from@example.com', to: 'to@example.com',
|
82
|
+
# subject: 'Test email', body: 'Test email body')
|
83
|
+
#
|
84
|
+
# MailPlugger::DeliveryMethod.new(
|
85
|
+
# delivery_settings: {
|
86
|
+
# smtp_settings: {
|
87
|
+
# address: 'smtp.server.com',
|
88
|
+
# port: 587,
|
89
|
+
# domain: 'test.domain.com',
|
90
|
+
# enable_starttls_auto: true,
|
91
|
+
# user_name: 'test_user',
|
92
|
+
# password: '1234',
|
93
|
+
# authentication: :plain
|
94
|
+
# }
|
95
|
+
# }
|
96
|
+
# ).deliver!(message)
|
97
|
+
#
|
98
|
+
# # Using API:
|
99
|
+
#
|
51
100
|
# MailPlugger.plug_in('test_api_client') do |api|
|
52
101
|
# api.delivery_options = %i[from to subject body]
|
53
102
|
# api.client = DefinedApiClientClass
|
@@ -76,7 +125,12 @@ module MailPlugger
|
|
76
125
|
|
77
126
|
@message = message
|
78
127
|
|
79
|
-
|
128
|
+
if send_via_smtp?
|
129
|
+
message.delivery_method :smtp, settings[:smtp_settings]
|
130
|
+
message.deliver!
|
131
|
+
else
|
132
|
+
client.new(delivery_data).deliver
|
133
|
+
end
|
80
134
|
end
|
81
135
|
end
|
82
136
|
end
|
@@ -5,6 +5,15 @@ require 'mail/indifferent_hash'
|
|
5
5
|
|
6
6
|
module MailPlugger
|
7
7
|
module MailHelper
|
8
|
+
DELIVERY_SETTINGS_KEYS = %i[
|
9
|
+
fake_plugger_debug
|
10
|
+
fake_plugger_raw_message
|
11
|
+
fake_plugger_response
|
12
|
+
fake_plugger_use_mail_grabber
|
13
|
+
return_response
|
14
|
+
smtp_settings
|
15
|
+
].freeze
|
16
|
+
|
8
17
|
# Check the version of a gem.
|
9
18
|
#
|
10
19
|
# @param [String] gem_name the name of the gem
|
@@ -64,11 +73,15 @@ module MailPlugger
|
|
64
73
|
end
|
65
74
|
|
66
75
|
# Tries to set up a default delivery system, if the 'delivery_system'
|
67
|
-
# wasn't defined in the Mail::Message object and '
|
68
|
-
#
|
69
|
-
#
|
76
|
+
# wasn't defined in the Mail::Message object and we're using
|
77
|
+
# MailPlugger.plug_in then it returns with first key of the stored
|
78
|
+
# 'delivery_systems'.
|
79
|
+
# When we are't using MailPlugger.plug_in method and 'delivery_options',
|
80
|
+
# 'client' and/or 'delivery_settings' is a hash, then it tries to get the
|
81
|
+
# 'delivery_system' from the hashes.
|
82
|
+
# Otherwise it returns with nil.
|
70
83
|
#
|
71
|
-
# @return [Stirng] the first key
|
84
|
+
# @return [Stirng/NilClass] the first key from the extracted keys or nil
|
72
85
|
def default_delivery_system_get
|
73
86
|
extract_keys&.first
|
74
87
|
end
|
@@ -91,7 +104,8 @@ module MailPlugger
|
|
91
104
|
|
92
105
|
# Extract 'delivery_system' from the Mail::Message object or if it's not
|
93
106
|
# defined then use the default one. If it's still nil and one of the
|
94
|
-
# 'delivery_options' or '
|
107
|
+
# 'delivery_options', 'client' and/or 'delivery_settings' is a hash and
|
108
|
+
# 'delivery_settings' doesn't contain 'delivery_system' then raise error.
|
95
109
|
#
|
96
110
|
# @return [String] with the name of the delivery system
|
97
111
|
def delivery_system
|
@@ -104,12 +118,13 @@ module MailPlugger
|
|
104
118
|
@delivery_system
|
105
119
|
end
|
106
120
|
|
107
|
-
# Check the given 'delivery_options'
|
108
|
-
# if one of that does then check the 'delivery_system' is valid
|
121
|
+
# Check the given 'delivery_options', 'client' and 'delivery_settings' are
|
122
|
+
# hashes and if one of that does then check the 'delivery_system' is valid
|
123
|
+
# or not.
|
109
124
|
# If the given 'delivery_system' is nil or doesn't match with extracted keys
|
110
125
|
# then it will raise error.
|
111
126
|
def delivery_system_value_check
|
112
|
-
return unless
|
127
|
+
return unless need_delivery_system?
|
113
128
|
|
114
129
|
if @delivery_system.nil?
|
115
130
|
raise Error::WrongDeliverySystem,
|
@@ -122,6 +137,17 @@ module MailPlugger
|
|
122
137
|
"\"delivery_system\" '#{@delivery_system}' does not exist"
|
123
138
|
end
|
124
139
|
|
140
|
+
# Check that 'delivery_settings' has 'delivery_system' key or not.
|
141
|
+
# If 'delivery_settings' contains 'DELIVERY_SETTINGS_KEYS' then it retruns
|
142
|
+
# false, else true.
|
143
|
+
#
|
144
|
+
# @return [Boolean] true/false
|
145
|
+
def exclude_delivey_settings_keys?
|
146
|
+
@delivery_settings.keys.none? do |key|
|
147
|
+
DELIVERY_SETTINGS_KEYS.include?(key.to_sym)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
125
151
|
# Extract attachments.
|
126
152
|
#
|
127
153
|
# @return [Array] with extracted attachment hashes
|
@@ -137,15 +163,28 @@ module MailPlugger
|
|
137
163
|
end
|
138
164
|
end
|
139
165
|
|
140
|
-
#
|
141
|
-
#
|
166
|
+
# Return 'delivery_systems' array if it's exist. If not then extract keys
|
167
|
+
# from 'delivery_options', 'client' or 'delivery_settings',
|
168
|
+
# depends on which is a hash. If none of these are hashes then returns nil.
|
142
169
|
#
|
143
|
-
# @return [Array/NilClass] with the keys
|
170
|
+
# @return [Array/NilClass] with the keys or nil
|
144
171
|
def extract_keys
|
172
|
+
return @delivery_systems unless @delivery_systems.nil?
|
173
|
+
|
174
|
+
extract_keys_from_other_variables
|
175
|
+
end
|
176
|
+
|
177
|
+
# Extract keys from 'delivery_options', 'client' or 'delivery_settings',
|
178
|
+
# depends on which is a hash. If none of these are hashes then returns nil.
|
179
|
+
#
|
180
|
+
# @return [Array/NilClass] with the keys from one of the hash or nil
|
181
|
+
def extract_keys_from_other_variables
|
145
182
|
if @delivery_options.is_a?(Hash)
|
146
183
|
@delivery_options
|
147
184
|
elsif @client.is_a?(Hash)
|
148
185
|
@client
|
186
|
+
elsif @delivery_settings.is_a?(Hash) && exclude_delivey_settings_keys?
|
187
|
+
@delivery_settings
|
149
188
|
end&.keys
|
150
189
|
end
|
151
190
|
|
@@ -174,6 +213,17 @@ module MailPlugger
|
|
174
213
|
message_field.public_send(*mail_field_value)
|
175
214
|
end
|
176
215
|
|
216
|
+
# Check if either 'deliviery_options' or 'client' is a hash.
|
217
|
+
# Or delivery_settings is a hash but not contains 'DELIVERY_SETTINGS_KEYS'
|
218
|
+
# in first level.
|
219
|
+
#
|
220
|
+
# @return [Boolean] true/false
|
221
|
+
def need_delivery_system?
|
222
|
+
@delivery_options.is_a?(Hash) ||
|
223
|
+
@client.is_a?(Hash) ||
|
224
|
+
(@delivery_settings.is_a?(Hash) && exclude_delivey_settings_keys?)
|
225
|
+
end
|
226
|
+
|
177
227
|
# Extract the value from the given options.
|
178
228
|
#
|
179
229
|
# @param [Hash/Array/Class] option
|
@@ -187,11 +237,22 @@ module MailPlugger
|
|
187
237
|
end
|
188
238
|
end
|
189
239
|
|
240
|
+
# Check that settings contains any SMTP related settings.
|
241
|
+
#
|
242
|
+
# @return [Boolean] true/false
|
243
|
+
def send_via_smtp?
|
244
|
+
return true if settings[:smtp_settings].is_a?(Hash) &&
|
245
|
+
settings[:smtp_settings].any?
|
246
|
+
|
247
|
+
false
|
248
|
+
end
|
249
|
+
|
190
250
|
# Extract 'settings'. If it's a hash then it'll return the right
|
191
|
-
# settings belongs to the delivery system. If
|
192
|
-
#
|
251
|
+
# settings belongs to the delivery system. If 'delivery_settings' is nil
|
252
|
+
# it'll return an empty hash. But if the value doesn't a hash it'll raise
|
253
|
+
# an error.
|
193
254
|
#
|
194
|
-
# @return [Hash] settings for Mail delivery_method
|
255
|
+
# @return [Hash] settings for Mail delivery_method and/or FakePlugger
|
195
256
|
def settings
|
196
257
|
@settings ||= option_value_from(@delivery_settings)
|
197
258
|
|
data/lib/mail_plugger/version.rb
CHANGED
data/lib/mail_plugger.rb
CHANGED
@@ -13,14 +13,35 @@ require 'fake_plugger/railtie' if defined?(Rails)
|
|
13
13
|
|
14
14
|
module MailPlugger
|
15
15
|
class << self
|
16
|
-
attr_reader :client,
|
16
|
+
attr_reader :client,
|
17
|
+
:delivery_options,
|
18
|
+
:delivery_settings,
|
19
|
+
:delivery_systems
|
17
20
|
|
18
|
-
# Plug in defined API(s) class.
|
21
|
+
# Plug in SMTP(s) or defined API(s) class.
|
19
22
|
#
|
20
|
-
# @param [String/Symbol] delivery_system the name of the API
|
23
|
+
# @param [String/Symbol] delivery_system the name of the SMTP/API
|
21
24
|
#
|
22
25
|
# @example using Rails `config/initializers/mail_plugger.rb`
|
23
26
|
#
|
27
|
+
# # Using SMTP:
|
28
|
+
#
|
29
|
+
# MailPlugger.plug_in('smtp_client') do |smtp|
|
30
|
+
# smtp.delivery_settings = {
|
31
|
+
# smtp_settings: {
|
32
|
+
# address: 'smtp.server.com',
|
33
|
+
# port: 587,
|
34
|
+
# domain: 'test.domain.com',
|
35
|
+
# enable_starttls_auto: true,
|
36
|
+
# user_name: 'test_user',
|
37
|
+
# password: '1234',
|
38
|
+
# authentication: :plain
|
39
|
+
# }
|
40
|
+
# }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # Using API:
|
44
|
+
#
|
24
45
|
# # The defined API class should have an 'initialize' and a 'deliver'
|
25
46
|
# # method.
|
26
47
|
# class DefinedApiClientClass
|
@@ -75,6 +96,7 @@ module MailPlugger
|
|
75
96
|
check_value(delivery_system)
|
76
97
|
|
77
98
|
@delivery_system = delivery_system
|
99
|
+
(@delivery_systems ||= []) << delivery_system
|
78
100
|
|
79
101
|
yield self
|
80
102
|
rescue NoMethodError => e
|
@@ -83,7 +105,7 @@ module MailPlugger
|
|
83
105
|
|
84
106
|
# Define 'client', 'delivery_options' and 'delivery_settings' setter
|
85
107
|
# methods. These methods are generating a hash where the key is the
|
86
|
-
# 'delivery_system'. This let us to set/use more than one API.
|
108
|
+
# 'delivery_system'. This let us to set/use more than one STMP/API.
|
87
109
|
%w[client delivery_options delivery_settings].each do |method|
|
88
110
|
define_method "#{method}=" do |value|
|
89
111
|
variable = instance_variable_get("@#{method}")
|
@@ -97,7 +119,7 @@ module MailPlugger
|
|
97
119
|
# Check 'delivery_system' is valid or not. If it's not valid then
|
98
120
|
# it will raise an error.
|
99
121
|
#
|
100
|
-
# @param [String/Symbol] delivery_system the name of the API
|
122
|
+
# @param [String/Symbol] delivery_system the name of the SMTP/API
|
101
123
|
def check_value(delivery_system)
|
102
124
|
if delivery_system.nil?
|
103
125
|
raise Error::WrongDeliverySystem, '"delivery_system" is nil'
|
@@ -110,7 +132,7 @@ module MailPlugger
|
|
110
132
|
return if delivery_system.is_a?(String) || delivery_system.is_a?(Symbol)
|
111
133
|
|
112
134
|
raise Error::WrongDeliverySystem, '"delivery_system" does not a ' \
|
113
|
-
|
135
|
+
'String or Symbol'
|
114
136
|
end
|
115
137
|
end
|
116
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_plugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norbert Szivós
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -24,8 +24,22 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.5'
|
27
|
-
|
28
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-smtp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.3'
|
41
|
+
description: Delivery Method to send emails via SMTP(s) and API(s). We can use this
|
42
|
+
Delivery Method with Ruby on Rails ActionMailer or other solutions.
|
29
43
|
email:
|
30
44
|
- sysqa@yahoo.com
|
31
45
|
executables: []
|
@@ -45,15 +59,16 @@ files:
|
|
45
59
|
- lib/mail_plugger/mail_helper.rb
|
46
60
|
- lib/mail_plugger/railtie.rb
|
47
61
|
- lib/mail_plugger/version.rb
|
48
|
-
homepage: https://github.com/
|
62
|
+
homepage: https://github.com/MailToolbox/mail_plugger
|
49
63
|
licenses:
|
50
64
|
- MIT
|
51
65
|
metadata:
|
52
|
-
homepage_uri: https://github.com/
|
53
|
-
source_code_uri: https://github.com/
|
54
|
-
changelog_uri: https://github.com/
|
55
|
-
bug_tracker_uri: https://github.com/
|
66
|
+
homepage_uri: https://github.com/MailToolbox/mail_plugger
|
67
|
+
source_code_uri: https://github.com/MailToolbox/mail_plugger
|
68
|
+
changelog_uri: https://github.com/MailToolbox/mail_plugger/blob/main/CHANGELOG.md
|
69
|
+
bug_tracker_uri: https://github.com/MailToolbox/mail_plugger/issues
|
56
70
|
documentation_uri: https://rubydoc.info/gems/mail_plugger
|
71
|
+
rubygems_mfa_required: 'true'
|
57
72
|
post_install_message:
|
58
73
|
rdoc_options: []
|
59
74
|
require_paths:
|
@@ -62,15 +77,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
77
|
requirements:
|
63
78
|
- - ">="
|
64
79
|
- !ruby/object:Gem::Version
|
65
|
-
version: 2.
|
80
|
+
version: 2.6.0
|
66
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
82
|
requirements:
|
68
83
|
- - ">="
|
69
84
|
- !ruby/object:Gem::Version
|
70
85
|
version: '0'
|
71
86
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.3.3
|
73
88
|
signing_key:
|
74
89
|
specification_version: 4
|
75
|
-
summary: Plug in
|
90
|
+
summary: Plug in required mailer SMTP(s) and API(s) with MailPlugger.
|
76
91
|
test_files: []
|