mailtrap 0.2.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +25 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +81 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +9 -17
- data/lib/mailtrap/sending/attachment.rb +52 -0
- data/lib/mailtrap/sending/client.rb +63 -0
- data/lib/mailtrap/sending/mail.rb +79 -0
- data/lib/mailtrap/sending.rb +23 -0
- data/lib/mailtrap/version.rb +5 -0
- data/lib/mailtrap.rb +4 -124
- metadata +58 -97
- data/History.txt +0 -5
- data/Manifest.txt +0 -6
- data/README.txt +0 -62
- data/bin/mailtrap +0 -28
- data/test/test_mailtrap.rb +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ab906395e1a92aac49d71c10d3e8935982997a51b05b52efd6ceee3c847e49a8
|
4
|
+
data.tar.gz: a86a0f2d5a265742d8801533c8c1566f2dd96af21af3d22197aea1dd7b788d4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2d3a90dabf85ebc515b5213a087c65eb6ca444c3848b913d550a4ebf937b5e318cecc8307261a2ae21f033e367bd5f3113d3191d7a0a4f70acd5e4ede738d20
|
7
|
+
data.tar.gz: 4d30beda4f75470bf4f3d72145d0ff1f0ed784261df3954de17fa56d3c54a9a77ebddead2d468e7b4f53172bf5df498fac773e92198ad033e474b5e139a53d09
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.7
|
5
|
+
NewCops: enable
|
6
|
+
|
7
|
+
Layout/LineLength:
|
8
|
+
Max: 120
|
9
|
+
|
10
|
+
Naming/MethodParameterName:
|
11
|
+
MinNameLength: 2
|
12
|
+
|
13
|
+
RSpec/MultipleExpectations:
|
14
|
+
Max: 4
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/StringLiterals:
|
20
|
+
Enabled: true
|
21
|
+
EnforcedStyle: single_quotes
|
22
|
+
|
23
|
+
Style/StringLiteralsInInterpolation:
|
24
|
+
Enabled: true
|
25
|
+
EnforcedStyle: double_quotes
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.6
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
|
22
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
23
|
+
* Public or private harassment
|
24
|
+
* Publishing others' private information, such as a physical or email address, without their explicit permission
|
25
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
26
|
+
|
27
|
+
## Enforcement Responsibilities
|
28
|
+
|
29
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
32
|
+
|
33
|
+
## Scope
|
34
|
+
|
35
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
36
|
+
|
37
|
+
## Enforcement
|
38
|
+
|
39
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at support@mailtrap.io. All complaints will be reviewed and investigated promptly and fairly.
|
40
|
+
|
41
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
42
|
+
|
43
|
+
## Enforcement Guidelines
|
44
|
+
|
45
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
46
|
+
|
47
|
+
### 1. Correction
|
48
|
+
|
49
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
50
|
+
|
51
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
52
|
+
|
53
|
+
### 2. Warning
|
54
|
+
|
55
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
56
|
+
|
57
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
58
|
+
|
59
|
+
### 3. Temporary Ban
|
60
|
+
|
61
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
62
|
+
|
63
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
64
|
+
|
65
|
+
### 4. Permanent Ban
|
66
|
+
|
67
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
68
|
+
|
69
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
70
|
+
|
71
|
+
## Attribution
|
72
|
+
|
73
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
74
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
75
|
+
|
76
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
77
|
+
|
78
|
+
[homepage]: https://www.contributor-covenant.org
|
79
|
+
|
80
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
81
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mailtrap (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
crack (0.4.5)
|
13
|
+
rexml
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
hashdiff (1.0.1)
|
16
|
+
parallel (1.22.1)
|
17
|
+
parser (3.1.2.0)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
public_suffix (4.0.7)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.0.6)
|
22
|
+
regexp_parser (2.4.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.11.0)
|
25
|
+
rspec-core (~> 3.11.0)
|
26
|
+
rspec-expectations (~> 3.11.0)
|
27
|
+
rspec-mocks (~> 3.11.0)
|
28
|
+
rspec-core (3.11.0)
|
29
|
+
rspec-support (~> 3.11.0)
|
30
|
+
rspec-expectations (3.11.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.11.0)
|
33
|
+
rspec-its (1.3.0)
|
34
|
+
rspec-core (>= 3.0.0)
|
35
|
+
rspec-expectations (>= 3.0.0)
|
36
|
+
rspec-mocks (3.11.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.11.0)
|
39
|
+
rspec-support (3.11.0)
|
40
|
+
rubocop (1.29.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 3.1.0.0)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
regexp_parser (>= 1.8, < 3.0)
|
45
|
+
rexml (>= 3.2.5, < 4.0)
|
46
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
49
|
+
rubocop-ast (1.18.0)
|
50
|
+
parser (>= 3.1.1.0)
|
51
|
+
rubocop-rspec (2.11.1)
|
52
|
+
rubocop (~> 1.19)
|
53
|
+
ruby-progressbar (1.11.0)
|
54
|
+
unicode-display_width (2.1.0)
|
55
|
+
vcr (6.1.0)
|
56
|
+
webmock (3.14.0)
|
57
|
+
addressable (>= 2.8.0)
|
58
|
+
crack (>= 0.3.2)
|
59
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
mailtrap!
|
66
|
+
rake (~> 13.0)
|
67
|
+
rspec (~> 3.0)
|
68
|
+
rspec-its
|
69
|
+
rubocop (~> 1.21)
|
70
|
+
rubocop-rspec
|
71
|
+
vcr
|
72
|
+
webmock
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Railsware Products Studio, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
[![test](https://github.com/railsware/mailtrap-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/railsware/mailtrap-ruby/actions/workflows/main.yml)
|
2
|
+
|
3
|
+
# Official Mailtrap Ruby client
|
4
|
+
|
5
|
+
This Ruby gem offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).
|
6
|
+
|
7
|
+
Quickly add email sending functionality to your Ruby application with Mailtrap.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'mailtrap'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install mailtrap
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Minimal
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'mailtrap'
|
31
|
+
|
32
|
+
# create mail object
|
33
|
+
mail = Mailtrap::Sending::Mail.new(
|
34
|
+
from: { email: 'mailtrap@example.com', name: 'Mailtrap Test' },
|
35
|
+
to: [
|
36
|
+
{ email: 'your@email.com' }
|
37
|
+
],
|
38
|
+
subject: 'You are awesome!',
|
39
|
+
text: "Congrats for sending test email with Mailtrap!"
|
40
|
+
)
|
41
|
+
|
42
|
+
# create client and send
|
43
|
+
client = Mailtrap::Sending::Client.new(api_key: 'your-api-key')
|
44
|
+
client.send(mail)
|
45
|
+
```
|
46
|
+
|
47
|
+
### Full
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'mailtrap'
|
51
|
+
require 'base64'
|
52
|
+
|
53
|
+
mail = Mailtrap::Sending::Mail.new(
|
54
|
+
from: { email: 'mailtrap@example.com', name: 'Mailtrap Test' },
|
55
|
+
to: [
|
56
|
+
{ email: 'your@email.com', name: 'Your name' }
|
57
|
+
],
|
58
|
+
cc: [
|
59
|
+
{ email: 'cc@email.com', name: 'Copy To' }
|
60
|
+
],
|
61
|
+
bcc: [
|
62
|
+
{ email: 'bcc@email.com', name: 'Hidden Recipient' }
|
63
|
+
],
|
64
|
+
subject: 'You are awesome!',
|
65
|
+
text: "Congrats for sending test email with Mailtrap!",
|
66
|
+
category: "Integration Test",
|
67
|
+
attachments: [
|
68
|
+
{
|
69
|
+
content: Base64.encode64('Attachment content'), # base64 encoded content or IO string
|
70
|
+
filename: 'attachment.txt'
|
71
|
+
}
|
72
|
+
],
|
73
|
+
headers: {
|
74
|
+
'X-MT-Header': 'Custom header'
|
75
|
+
},
|
76
|
+
custom_variables: {
|
77
|
+
year: 2022
|
78
|
+
}
|
79
|
+
)
|
80
|
+
|
81
|
+
data = File.open('/path/to/image.jpg').read
|
82
|
+
encoded = Base64.encode64(data).gsub(/\n/,"")
|
83
|
+
|
84
|
+
mail.add_attachment(content: encoded, filename: 'image.png')
|
85
|
+
|
86
|
+
client = Mailtrap::Sending::Client.new(api_key: 'your-api-key')
|
87
|
+
client.send(mail)
|
88
|
+
```
|
89
|
+
|
90
|
+
## Development
|
91
|
+
|
92
|
+
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.
|
93
|
+
|
94
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
103
|
+
|
104
|
+
## Code of Conduct
|
105
|
+
|
106
|
+
Everyone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require './lib/mailtrap.rb'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
6
5
|
|
7
|
-
|
8
|
-
p.rubyforge_name = 'rubymatt'
|
9
|
-
p.author = 'Matt Mower'
|
10
|
-
p.email = 'self@mattmower.com'
|
11
|
-
p.summary = 'Mailtrap is a mock SMTP server for use in Rails development'
|
12
|
-
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
-
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
-
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
-
p.remote_rdoc_dir = 'mailtrap'
|
16
|
-
p.extra_deps << ['daemons','>= 1.0.8']
|
17
|
-
p.extra_deps << ['trollop','>= 1.7']
|
18
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
19
7
|
|
20
|
-
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Mailtrap
|
7
|
+
module Sending
|
8
|
+
class Attachment
|
9
|
+
attr_accessor :type, :filename, :disposition, :content_id
|
10
|
+
attr_reader :content
|
11
|
+
|
12
|
+
def initialize(content:, filename:, type: nil, disposition: nil, content_id: nil)
|
13
|
+
self.content = content
|
14
|
+
@type = type
|
15
|
+
@filename = filename
|
16
|
+
@disposition = disposition
|
17
|
+
@content_id = content_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_json
|
21
|
+
{
|
22
|
+
'content' => content,
|
23
|
+
'type' => type,
|
24
|
+
'filename' => filename,
|
25
|
+
'disposition' => disposition,
|
26
|
+
'content_id' => content_id
|
27
|
+
}.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def content=(content)
|
31
|
+
if content.respond_to?(:read)
|
32
|
+
@content = encode(content)
|
33
|
+
else
|
34
|
+
raise AttachmentContentError unless base64?(content)
|
35
|
+
|
36
|
+
@content = content
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def encode(io)
|
43
|
+
string = io.read.encode('UTF-8') unless io.respond_to?(:binmode?) && io.binmode?
|
44
|
+
Base64.encode64(string).gsub(/\n/, '')
|
45
|
+
end
|
46
|
+
|
47
|
+
def base64?(string)
|
48
|
+
string.is_a?(String) && Base64.strict_encode64(Base64.decode64(string)) == string
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module Mailtrap
|
8
|
+
module Sending
|
9
|
+
class Client
|
10
|
+
API_HOST = 'send.api.mailtrap.io'
|
11
|
+
API_PORT = 443
|
12
|
+
|
13
|
+
attr_reader :api_key, :api_host, :api_port
|
14
|
+
|
15
|
+
def initialize(api_key: ENV.fetch('MAILTRAP_API_KEY'), api_host: API_HOST, api_port: API_PORT)
|
16
|
+
@api_key = api_key
|
17
|
+
@api_host = api_host
|
18
|
+
@api_port = api_port
|
19
|
+
end
|
20
|
+
|
21
|
+
def send(mail)
|
22
|
+
raise ArgumentError, 'should be Mailtrap::Sending::Mail object' unless mail.is_a? Mailtrap::Sending::Mail
|
23
|
+
|
24
|
+
request = post_request('/api/send', mail.to_json)
|
25
|
+
response = http_client.request(request)
|
26
|
+
|
27
|
+
handle_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def http_client
|
33
|
+
@http_client ||= Net::HTTP.new(API_HOST, API_PORT).tap { |client| client.use_ssl = true }
|
34
|
+
end
|
35
|
+
|
36
|
+
def post_request(path, body)
|
37
|
+
request = Net::HTTP::Post.new(path)
|
38
|
+
request.body = body
|
39
|
+
request['Authorization'] = "Bearer #{api_key}"
|
40
|
+
request['Content-Type'] = 'application/json'
|
41
|
+
|
42
|
+
request
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_response(response)
|
46
|
+
case response.code
|
47
|
+
when '200'
|
48
|
+
json_response(response.body)
|
49
|
+
when '400'
|
50
|
+
raise Mailtrap::Sending::Error, json_response(response.body)[:errors]
|
51
|
+
when '401'
|
52
|
+
raise Mailtrap::Sending::AuthorizationError, json_response(response.body)[:errors]
|
53
|
+
else
|
54
|
+
raise Mailtrap::Sending::Error, ['server error']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def json_response(body)
|
59
|
+
JSON.parse(body, symbolize_names: true)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Mailtrap
|
6
|
+
module Sending
|
7
|
+
class Mail
|
8
|
+
attr_accessor :from, :to, :cc, :bcc, :subject, :text, :html, :headers, :category, :custom_variables
|
9
|
+
attr_reader :attachments
|
10
|
+
|
11
|
+
def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
|
12
|
+
from: nil,
|
13
|
+
to: [],
|
14
|
+
cc: [],
|
15
|
+
bcc: [],
|
16
|
+
subject: nil,
|
17
|
+
text: nil,
|
18
|
+
html: nil,
|
19
|
+
attachments: [],
|
20
|
+
headers: {},
|
21
|
+
category: nil,
|
22
|
+
custom_variables: {}
|
23
|
+
)
|
24
|
+
@from = from
|
25
|
+
@to = to
|
26
|
+
@cc = cc
|
27
|
+
@bcc = bcc
|
28
|
+
@subject = subject
|
29
|
+
@text = text
|
30
|
+
@html = html
|
31
|
+
self.attachments = attachments
|
32
|
+
@headers = headers
|
33
|
+
@category = category
|
34
|
+
@custom_variables = custom_variables
|
35
|
+
end
|
36
|
+
|
37
|
+
def as_json # rubocop:disable Metrics/MethodLength
|
38
|
+
{
|
39
|
+
'to' => to,
|
40
|
+
'from' => from,
|
41
|
+
'cc' => cc,
|
42
|
+
'bcc' => bcc,
|
43
|
+
'subject' => subject,
|
44
|
+
'html' => html,
|
45
|
+
'text' => text,
|
46
|
+
'attachments' => attachments.map(&:as_json),
|
47
|
+
# TODO: update headers and custom_variables with as_json method
|
48
|
+
'headers' => headers,
|
49
|
+
'category' => category,
|
50
|
+
'custom_variables' => custom_variables
|
51
|
+
}.compact
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_json(*args)
|
55
|
+
JSON.generate(
|
56
|
+
as_json,
|
57
|
+
*args
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def attachments=(attachments)
|
62
|
+
@attachments = attachments.map { |attachment| Mailtrap::Sending::Attachment.new(**attachment) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_attachment(content:, filename:, type: nil, disposition: nil, content_id: nil)
|
66
|
+
attachment = Mailtrap::Sending::Attachment.new(
|
67
|
+
content: content,
|
68
|
+
filename: filename,
|
69
|
+
type: type,
|
70
|
+
disposition: disposition,
|
71
|
+
content_id: content_id
|
72
|
+
)
|
73
|
+
attachments << attachment
|
74
|
+
|
75
|
+
attachment
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sending/attachment'
|
4
|
+
require_relative 'sending/client'
|
5
|
+
require_relative 'sending/mail'
|
6
|
+
|
7
|
+
module Mailtrap
|
8
|
+
module Sending
|
9
|
+
class AttachmentContentError < StandardError; end
|
10
|
+
|
11
|
+
class Error < StandardError
|
12
|
+
attr_reader :messages
|
13
|
+
|
14
|
+
def initialize(messages)
|
15
|
+
@messages = messages
|
16
|
+
|
17
|
+
super(messages.join(', '))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class AuthorizationError < Error; end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mailtrap.rb
CHANGED
@@ -1,126 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
|
3
|
-
|
4
|
-
require 'socket'
|
5
|
-
require 'trollop'
|
3
|
+
require_relative 'mailtrap/sending'
|
4
|
+
require_relative 'mailtrap/version'
|
6
5
|
|
7
|
-
|
8
|
-
# Mailtrap creates a TCP server that listens on a specified port for SMTP
|
9
|
-
# clients. Accepts the connection and talks just enough of the SMTP protocol
|
10
|
-
# for them to deliver a message which it writes to disk.
|
11
|
-
#
|
12
|
-
class Mailtrap
|
13
|
-
VERSION = '0.2.0'
|
14
|
-
|
15
|
-
# Create a new Mailtrap on the specified host:port. If once it true it
|
16
|
-
# will listen for one message then exit. Specify the msgdir where messages
|
17
|
-
# are written.
|
18
|
-
def initialize( host, port, once, msgfile )
|
19
|
-
@host = host
|
20
|
-
@port = port
|
21
|
-
@once = once
|
22
|
-
@msgfile = msgfile
|
23
|
-
|
24
|
-
puts "Mailtrap starting at #{@host}:#{port} and writing to #{@msgfile}"
|
25
|
-
service = TCPServer.new( @host, @port )
|
26
|
-
accept( service )
|
27
|
-
end
|
28
|
-
|
29
|
-
# Service one or more SMTP client connections
|
30
|
-
def accept( service )
|
31
|
-
while session = service.accept
|
32
|
-
|
33
|
-
class << session
|
34
|
-
def get_line
|
35
|
-
line = gets
|
36
|
-
line.chomp! unless line.nil?
|
37
|
-
line
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
begin
|
42
|
-
serve( session )
|
43
|
-
rescue Exception => e
|
44
|
-
puts "Erk! #{e.message}"
|
45
|
-
end
|
46
|
-
|
47
|
-
break if @once
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Write a plain text dump of the incoming email to a text
|
52
|
-
# file. The file will be in the @msgdir folder and will
|
53
|
-
# be called smtp0001.msg, smtp0002.msg, and so on.
|
54
|
-
def write( from, to_list, message )
|
55
|
-
|
56
|
-
# Strip SMTP commands from To: and From:
|
57
|
-
from.gsub!( /MAIL FROM:\s*/, "" )
|
58
|
-
to_list = to_list.map { |to| to.gsub( /RCPT TO:\s*/, "" ) }
|
59
|
-
|
60
|
-
# Append to the end of the messages file
|
61
|
-
File.open( @msgfile, "a" ) do |file|
|
62
|
-
file.puts "****************************************"
|
63
|
-
file.puts "From: #{from}"
|
64
|
-
file.puts "To: #{to_list.join(", ")}"
|
65
|
-
file.puts "Body:"
|
66
|
-
file.puts message
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
# Talk pidgeon-SMTP to the client to get them to hand over the message
|
72
|
-
# and go away.
|
73
|
-
def serve( connection )
|
74
|
-
connection.puts( "220 #{@host} MailTrap ready ESTMP" )
|
75
|
-
helo = connection.get_line # whoever they are
|
76
|
-
puts "Helo: #{helo}"
|
77
|
-
|
78
|
-
if helo =~ /^EHLO\s+/
|
79
|
-
puts "Seen an EHLO"
|
80
|
-
connection.puts "250-#{@host} offers just ONE extension my pretty"
|
81
|
-
connection.puts "250 HELP"
|
82
|
-
end
|
83
|
-
|
84
|
-
# Accept MAIL FROM:
|
85
|
-
from = connection.get_line
|
86
|
-
connection.puts( "250 OK" )
|
87
|
-
puts "From: #{from}"
|
88
|
-
|
89
|
-
to_list = []
|
90
|
-
|
91
|
-
# Accept RCPT TO: until we see DATA
|
92
|
-
loop do
|
93
|
-
to = connection.get_line
|
94
|
-
break if to.nil?
|
95
|
-
|
96
|
-
if to =~ /^DATA/
|
97
|
-
connection.puts( "354 Start your message" )
|
98
|
-
break
|
99
|
-
else
|
100
|
-
puts "To: #{to}"
|
101
|
-
to_list << to
|
102
|
-
connection.puts( "250 OK" )
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Capture the message body terminated by <CR>.<CR>
|
107
|
-
lines = []
|
108
|
-
loop do
|
109
|
-
line = connection.get_line
|
110
|
-
break if line.nil? || line == "."
|
111
|
-
lines << line
|
112
|
-
puts "+ #{line}"
|
113
|
-
end
|
114
|
-
|
115
|
-
# We expect the client will go away now
|
116
|
-
connection.puts( "250 OK" )
|
117
|
-
connection.gets # Quit
|
118
|
-
connection.puts "221 Seeya"
|
119
|
-
connection.close
|
120
|
-
puts "And we're done with that bozo!"
|
121
|
-
|
122
|
-
write( from, to_list, lines.join( "\n" ) )
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
6
|
+
module Mailtrap; end
|
metadata
CHANGED
@@ -1,102 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
1
|
+
--- !ruby/object:Gem::Specification
|
4
2
|
name: mailtrap
|
5
|
-
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-10-04 00:00:00 +01:00
|
8
|
-
summary: Mailtrap is a mock SMTP server for use in Rails development
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: self@mattmower.com
|
12
|
-
homepage: " by Matt Mower <self@mattmower.com>"
|
13
|
-
rubyforge_project: rubymatt
|
14
|
-
description: "Mailtrap is a mock SMTP server for use in Rails development. Mailtrap waits on your choosen port for a client to connect and talks _just enough_ SMTP protocol for ActionMailer to successfully deliver its message. Mailtrap makes *no* attempt to actually deliver messages and, instead, writes them into sequentially numbered files on disk (hence the name \tMail_trap_). You can configure the hostname (default: localhost) and port (default: 2525) for the server and also where the messages get written (default: /var/tmp). Messages will get written to files named smtp0001.msg, smtp0002.msg, and so on. == FEATURES/PROBLEMS:"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
25
5
|
platform: ruby
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
post_install_message:
|
51
|
-
authors:
|
52
|
-
- Matt Mower
|
53
|
-
files:
|
54
|
-
- History.txt
|
55
|
-
- Manifest.txt
|
56
|
-
- README.txt
|
6
|
+
authors:
|
7
|
+
- Railsware Products Studio, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Official mailtrap.io API client
|
14
|
+
email:
|
15
|
+
- support@mailtrap.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- ".ruby-version"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
57
29
|
- Rakefile
|
58
|
-
- bin/mailtrap
|
59
30
|
- lib/mailtrap.rb
|
60
|
-
|
61
|
-
-
|
62
|
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
|
66
|
-
|
67
|
-
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
31
|
+
- lib/mailtrap/sending.rb
|
32
|
+
- lib/mailtrap/sending/attachment.rb
|
33
|
+
- lib/mailtrap/sending/client.rb
|
34
|
+
- lib/mailtrap/sending/mail.rb
|
35
|
+
- lib/mailtrap/version.rb
|
36
|
+
homepage: https://github.com/railsware/mailtrap-ruby
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/railsware/mailtrap-ruby
|
41
|
+
source_code_uri: https://github.com/railsware/mailtrap-ruby
|
42
|
+
changelog_uri: https://github.com/railsware/mailtrap-ruby/blob/main/CHANGELOG.md
|
43
|
+
rubygems_mfa_required: 'true'
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.7.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
73
58
|
requirements: []
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 1.0.8
|
84
|
-
version:
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: trollop
|
87
|
-
version_requirement:
|
88
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
89
|
-
requirements:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: "1.7"
|
93
|
-
version:
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: hoe
|
96
|
-
version_requirement:
|
97
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
98
|
-
requirements:
|
99
|
-
- - ">="
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 1.3.0
|
102
|
-
version:
|
59
|
+
rubygems_version: 3.1.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Official mailtrap.io API client
|
63
|
+
test_files: []
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
mailtrap
|
2
|
-
by Matt Mower <self@mattmower.com>
|
3
|
-
http://matt.blogs.it/
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Mailtrap is a mock SMTP server for use in Rails development.
|
8
|
-
|
9
|
-
Mailtrap waits on your choosen port for a client to connect and talks _just enough_ SMTP protocol for ActionMailer to successfully deliver its message.
|
10
|
-
|
11
|
-
Mailtrap makes *no* attempt to actually deliver messages and, instead, writes them into sequentially numbered files on disk (hence the name Mail_trap_).
|
12
|
-
|
13
|
-
You can configure the hostname (default: localhost) and port (default: 2525) for the server and also where the messages get written (default: /var/tmp). Messages will get written to files named smtp0001.msg, smtp0002.msg, and so on.
|
14
|
-
|
15
|
-
== FEATURES/PROBLEMS:
|
16
|
-
|
17
|
-
* Lightweight, no setup
|
18
|
-
* Runs as a daemon with start, stop, etc..
|
19
|
-
* Tested with ActionMailer's SMTP delivery method
|
20
|
-
* Very, very, dumb ... might not work with an arbitrary SMTP client
|
21
|
-
|
22
|
-
== SYNOPSIS:
|
23
|
-
|
24
|
-
* mailtrap --help (to see Daemonization options)
|
25
|
-
* mailtrap start --help (to see Mailtrap options)
|
26
|
-
|
27
|
-
* mailtrap start --host localhost --port 8025 --once --msgdir=/var/tmp
|
28
|
-
|
29
|
-
== REQUIREMENTS:
|
30
|
-
|
31
|
-
* Rubygems
|
32
|
-
* Daemons rubygem
|
33
|
-
* Trollop rubygem
|
34
|
-
|
35
|
-
== INSTALL:
|
36
|
-
|
37
|
-
* sudo gem install -y mailtrap
|
38
|
-
|
39
|
-
== LICENSE:
|
40
|
-
|
41
|
-
(The MIT License)
|
42
|
-
|
43
|
-
Copyright (c) 2007 Matt Mower, Software Heretics
|
44
|
-
|
45
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
-
a copy of this software and associated documentation files (the
|
47
|
-
'Software'), to deal in the Software without restriction, including
|
48
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
-
permit persons to whom the Software is furnished to do so, subject to
|
51
|
-
the following conditions:
|
52
|
-
|
53
|
-
The above copyright notice and this permission notice shall be
|
54
|
-
included in all copies or substantial portions of the Software.
|
55
|
-
|
56
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/mailtrap
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# Run the mailtrap server
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'daemons'
|
8
|
-
require 'mailtrap'
|
9
|
-
|
10
|
-
opts = Trollop::options do
|
11
|
-
opt :host, "The host SMTP clients will connect to", :default => 'localhost'
|
12
|
-
opt :port, "The port SMTP clients will connect to", :default => 2525
|
13
|
-
opt :once, "Whether to terminate after serving the first client", :default => false
|
14
|
-
opt :file, "File where messages get written", :default => "/var/tmp/mailtrap.log"
|
15
|
-
end
|
16
|
-
|
17
|
-
options = {
|
18
|
-
:dir_mode => :normal,
|
19
|
-
:dir => '/var/tmp',
|
20
|
-
:multiple => true,
|
21
|
-
:mode => :exec,
|
22
|
-
:backtrace => true,
|
23
|
-
:log_output => true
|
24
|
-
}
|
25
|
-
|
26
|
-
Daemons.run_proc( 'mailtrap', options ) do
|
27
|
-
Mailtrap.new( opts[:host], opts[:port], opts[:once], opts[:file] )
|
28
|
-
end
|
data/test/test_mailtrap.rb
DELETED
File without changes
|
data.tar.gz.sig
DELETED
Binary file
|
metadata.gz.sig
DELETED
Binary file
|