mailtrap 1.0.1 → 1.1.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/.rubocop.yml +3 -0
- data/CHANGELOG.md +5 -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/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 +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd604b5702f48dbaa0cf3fb294c3d000af11891ca3e0d6453af0763c1aa0abd4
|
4
|
+
data.tar.gz: 66baa71b1a5cb26cbd4012f6b6a4ab10fd585850f93792ffc9b2776bde9019ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853e6421d2d5d3c02bd0b090b4810383b5b30e6b8bfc178379ea602e56eb44ba1b298a2bb8e87575abfd0a37bc110a5bb8c8d14ca78d3c75729974cf389b2fd6
|
7
|
+
data.tar.gz: b9ca3ed482f8077a35151237a6078ef88ce2cdc58f1f097f72730f6fe71eb7367235559ebbbeba24b1622a06af10f31c728deb93ee6ef4207d6091543e5944bb
|
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.0
|
4
|
+
mailtrap (1.1.0)
|
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
|
@@ -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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Railsware Products Studio, Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-01 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
|
@@ -41,7 +46,7 @@ metadata:
|
|
41
46
|
source_code_uri: https://github.com/railsware/mailtrap-ruby
|
42
47
|
changelog_uri: https://github.com/railsware/mailtrap-ruby/blob/main/CHANGELOG.md
|
43
48
|
rubygems_mfa_required: 'true'
|
44
|
-
post_install_message:
|
49
|
+
post_install_message:
|
45
50
|
rdoc_options: []
|
46
51
|
require_paths:
|
47
52
|
- lib
|
@@ -57,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
62
|
version: '0'
|
58
63
|
requirements: []
|
59
64
|
rubygems_version: 3.1.6
|
60
|
-
signing_key:
|
65
|
+
signing_key:
|
61
66
|
specification_version: 4
|
62
67
|
summary: Official mailtrap.io API client
|
63
68
|
test_files: []
|