mailtrap 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +7 -1
- data/README.md +21 -0
- data/lib/mailtrap/action_mailer/delivery_method.rb +25 -0
- data/lib/mailtrap/action_mailer/railtie.rb +13 -0
- data/lib/mailtrap/action_mailer.rb +8 -0
- data/lib/mailtrap/sending/client.rb +1 -1
- data/lib/mailtrap/sending/convert.rb +83 -0
- data/lib/mailtrap/sending.rb +1 -0
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap.rb +1 -0
- data/mailtrap.gemspec +30 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23acecf40de87c9ec6c68cee1a63244548f699819ce122b9f37877e6429a25e9
|
4
|
+
data.tar.gz: 5e2009cefd12428d8274ac79a57644f3b5bfcd6b4e266afc62ee5d274b22daa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00157801f3ae86ee16ffb51850c4af77f0213d736371fffacd3799c045f60955455f27c03283d8df16b41c5f0c635cfc22c1808c7d268c7b40c3d2ccd672e92c'
|
7
|
+
data.tar.gz: f8b80546c0dd317a64882cfb61ddbc8e646057da495508913fbefc9f26cd75a71129d807752a3cd41aa4df5ad38888e7c4a06247d2bbce8233af52d6507aa3e3
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mailtrap (1.
|
4
|
+
mailtrap (1.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -13,6 +13,10 @@ GEM
|
|
13
13
|
rexml
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
hashdiff (1.0.1)
|
16
|
+
mail (2.7.1)
|
17
|
+
mini_mime (>= 0.1.1)
|
18
|
+
mini_mime (1.1.2)
|
19
|
+
net-smtp (0.1.0)
|
16
20
|
parallel (1.22.1)
|
17
21
|
parser (3.1.2.0)
|
18
22
|
ast (~> 2.4.1)
|
@@ -62,7 +66,9 @@ PLATFORMS
|
|
62
66
|
ruby
|
63
67
|
|
64
68
|
DEPENDENCIES
|
69
|
+
mail
|
65
70
|
mailtrap!
|
71
|
+
net-smtp
|
66
72
|
rake (~> 13.0)
|
67
73
|
rspec (~> 3.0)
|
68
74
|
rspec-its
|
data/README.md
CHANGED
@@ -87,6 +87,27 @@ client = Mailtrap::Sending::Client.new(api_key: 'your-api-key')
|
|
87
87
|
client.send(mail)
|
88
88
|
```
|
89
89
|
|
90
|
+
### ActionMailer
|
91
|
+
|
92
|
+
This gem also adds ActionMailer delivery method. To configure it, add following to your ActionMailer configuration (in Rails projects located in `config/$ENVIRONMENT.rb`):
|
93
|
+
```ruby
|
94
|
+
config.action_mailer.delivery_method = :mailtrap
|
95
|
+
config.action_mailer.mailtrap_settings = {
|
96
|
+
api_key: ENV.fetch('MAILTRAP_API_KEY')
|
97
|
+
}
|
98
|
+
```
|
99
|
+
And continue to use ActionMailer as usual.
|
100
|
+
|
101
|
+
To add `category` and `custom_variables`, add them to the mail generation:
|
102
|
+
```ruby
|
103
|
+
mail(
|
104
|
+
to: 'your@email.com',
|
105
|
+
subject: 'You are awesome!',
|
106
|
+
category: 'Test category',
|
107
|
+
custom_variables: { test_variable: 'abc' }
|
108
|
+
)
|
109
|
+
```
|
110
|
+
|
90
111
|
## Development
|
91
112
|
|
92
113
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mailtrap
|
4
|
+
module ActionMailer
|
5
|
+
class DeliveryMethod
|
6
|
+
attr_accessor :settings
|
7
|
+
|
8
|
+
def initialize(settings)
|
9
|
+
self.settings = settings
|
10
|
+
end
|
11
|
+
|
12
|
+
def deliver!(message)
|
13
|
+
mail = Mailtrap::Sending::Convert.from_message(message)
|
14
|
+
|
15
|
+
client.send(mail)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def client
|
21
|
+
@client ||= Mailtrap::Sending::Client.new(**settings.slice(:api_key, :api_host, :api_port))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mailtrap
|
4
|
+
module ActionMailer
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer 'mailtrap_action_mailer.add_delivery_method', before: 'action_mailer.set_configs' do
|
7
|
+
ActiveSupport.on_load(:action_mailer) do
|
8
|
+
::ActionMailer::Base.add_delivery_method(:mailtrap, Mailtrap::ActionMailer::DeliveryMethod)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -30,7 +30,7 @@ module Mailtrap
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def http_client
|
33
|
-
@http_client ||= Net::HTTP.new(
|
33
|
+
@http_client ||= Net::HTTP.new(api_host, api_port).tap { |client| client.use_ssl = true }
|
34
34
|
end
|
35
35
|
|
36
36
|
def post_request(path, body)
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Mailtrap
|
6
|
+
module Sending
|
7
|
+
module Convert
|
8
|
+
class << self
|
9
|
+
def from_message(message) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
10
|
+
Mailtrap::Sending::Mail.new(
|
11
|
+
from: prepare_address(message['from']&.address_list&.addresses&.first),
|
12
|
+
to: prepare_addresses(message['to']&.address_list&.addresses),
|
13
|
+
cc: prepare_addresses(message['cc']&.address_list&.addresses),
|
14
|
+
bcc: prepare_addresses(message['bcc']&.address_list&.addresses),
|
15
|
+
subject: message.subject,
|
16
|
+
text: prepare_text_part(message),
|
17
|
+
html: prepare_html_part(message),
|
18
|
+
headers: prepare_headers(message),
|
19
|
+
attachments: prepare_attachments(message.attachments),
|
20
|
+
category: message['category']&.unparsed_value,
|
21
|
+
custom_variables: message['custom_variables']&.unparsed_value
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
PROCESSED_HEADERS = %w[
|
28
|
+
from
|
29
|
+
to
|
30
|
+
cc
|
31
|
+
bcc
|
32
|
+
subject
|
33
|
+
category
|
34
|
+
customvariables
|
35
|
+
contenttype
|
36
|
+
].freeze
|
37
|
+
|
38
|
+
def prepare_addresses(addresses)
|
39
|
+
Array(addresses).map { |address| prepare_address(address) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def prepare_headers(message)
|
43
|
+
message
|
44
|
+
.header_fields
|
45
|
+
.reject { |header| PROCESSED_HEADERS.include?(header.name.downcase.delete('-')) }
|
46
|
+
.to_h { |header| [header.name, header.value] }
|
47
|
+
.compact
|
48
|
+
end
|
49
|
+
|
50
|
+
def prepare_address(address)
|
51
|
+
{
|
52
|
+
email: address.address,
|
53
|
+
name: address.display_name
|
54
|
+
}.compact
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_attachments(attachments_list = [])
|
58
|
+
attachments_list.map do |attachment|
|
59
|
+
{
|
60
|
+
content: Base64.strict_encode64(attachment.body.decoded),
|
61
|
+
type: attachment.mime_type,
|
62
|
+
filename: attachment.filename,
|
63
|
+
disposition: attachment.header[:content_disposition]&.disposition_type,
|
64
|
+
content_id: attachment.header[:content_id]&.field&.content_id
|
65
|
+
}.compact
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def prepare_html_part(message)
|
70
|
+
return message.body.decoded if message.mime_type == 'text/html'
|
71
|
+
|
72
|
+
message.html_part&.decoded
|
73
|
+
end
|
74
|
+
|
75
|
+
def prepare_text_part(message)
|
76
|
+
return message.body.decoded if message.mime_type == 'text/plain' || message.mime_type.nil?
|
77
|
+
|
78
|
+
message.text_part&.decoded
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/mailtrap/sending.rb
CHANGED
data/lib/mailtrap/version.rb
CHANGED
data/lib/mailtrap.rb
CHANGED
data/mailtrap.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/mailtrap/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mailtrap'
|
7
|
+
spec.version = Mailtrap::VERSION
|
8
|
+
spec.authors = ['Railsware Products Studio, Inc.']
|
9
|
+
spec.email = ['support@mailtrap.io']
|
10
|
+
|
11
|
+
spec.summary = 'Official mailtrap.io API client'
|
12
|
+
spec.description = 'Official mailtrap.io API client'
|
13
|
+
spec.homepage = 'https://github.com/railsware/mailtrap-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 2.7.0'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/railsware/mailtrap-ruby'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/railsware/mailtrap-ruby/blob/main/CHANGELOG.md'
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|github|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailtrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Railsware Products Studio, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Official mailtrap.io API client
|
14
14
|
email:
|
@@ -28,11 +28,16 @@ files:
|
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
30
|
- lib/mailtrap.rb
|
31
|
+
- lib/mailtrap/action_mailer.rb
|
32
|
+
- lib/mailtrap/action_mailer/delivery_method.rb
|
33
|
+
- lib/mailtrap/action_mailer/railtie.rb
|
31
34
|
- lib/mailtrap/sending.rb
|
32
35
|
- lib/mailtrap/sending/attachment.rb
|
33
36
|
- lib/mailtrap/sending/client.rb
|
37
|
+
- lib/mailtrap/sending/convert.rb
|
34
38
|
- lib/mailtrap/sending/mail.rb
|
35
39
|
- lib/mailtrap/version.rb
|
40
|
+
- mailtrap.gemspec
|
36
41
|
homepage: https://github.com/railsware/mailtrap-ruby
|
37
42
|
licenses:
|
38
43
|
- MIT
|