ohmysmtp-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +92 -0
- data/Rakefile +27 -0
- data/lib/ohmysmtp-rails.rb +62 -0
- data/lib/ohmysmtp-rails/railtie.rb +7 -0
- data/lib/ohmysmtp-rails/version.rb +5 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 056dbcc06cf514f4ea4ab5b24eb3606a7b170ffd485c32aead49088b4e2666ef
|
4
|
+
data.tar.gz: 54faecc5475e5fb710bc63242c80e287cfc0be004ba0cdf4eecdcf14eaf428b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2fb219e0e85ce7e3df8431b96f2abad253439a5ef51c2d4b8e367c1e6eec6f6b0c1cfb76bcbf8c2cf4090171dfdedf256689c206b0edad17355b3c11fb71db36
|
7
|
+
data.tar.gz: 29d62a2f03de60de38187c8e6dfcf4509d34b04dcbbecb05c1bbae757156f2ce72ee7184f9faf271841038537a04c980900f6b941ebdec76e1a9841f11753d96
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 OhMySMTP
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# OhMySMTP::Rails
|
2
|
+
|
3
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
|
4
|
+
|
5
|
+
|
6
|
+
[OhMySMTP](https://ohmysmtp.com) lets you send transactional emails from your app over an easy to use API.
|
7
|
+
|
8
|
+
The OhMySMTP Rails Gem is a plug in for ActionMailer to send emails via [OhMySMTP](https://ohmysmtp.com) to make sending emails from Rails apps super simple.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Once installed and configured, continue to send emails using [ActionMailer](https://guides.rubyonrails.org/action_mailer_basics.html) like normal.
|
13
|
+
|
14
|
+
## Requirements
|
15
|
+
|
16
|
+
You will need an OhMySMTP account with a verified domain and organization with an active plan.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
### Account Setup
|
21
|
+
|
22
|
+
Set up an account at [OhMySMTP](https://app.ohmysmtp.com/users/sign_up) and complete the Onboarding steps
|
23
|
+
|
24
|
+
### Gem Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'ohmysmtp-rails'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
```bash
|
34
|
+
$ bundle
|
35
|
+
```
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
```bash
|
39
|
+
$ gem install ohmysmtp-rails
|
40
|
+
```
|
41
|
+
|
42
|
+
### Configure the Gem
|
43
|
+
|
44
|
+
First you will need to retrieve your API token for your sending domain from [OhMySMTP](https://app.ohmysmtp.com). You can find it under Organization -> Domain -> API Tokens
|
45
|
+
|
46
|
+
#### Rails 6
|
47
|
+
|
48
|
+
Use the encrypted secret management to save your API Token to `config/credentials.yml.enc` by running the following:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
rails secret
|
52
|
+
rails credentials:edit
|
53
|
+
```
|
54
|
+
|
55
|
+
Then add your token:
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
ohmysmtp_api_token: "TOKEN_GOES_HERE"
|
59
|
+
```
|
60
|
+
|
61
|
+
Set OhMySMTP as your mail delivery method in `config/application.rb`:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
config.action_mailer.delivery_method = :ohmysmtp
|
65
|
+
config.action_mailer.ohmysmtp_settings = { api_token: Rails.application.credentials.ohmysmtp_api_token }
|
66
|
+
```
|
67
|
+
|
68
|
+
#### Rails 3-5
|
69
|
+
|
70
|
+
Save your API Token to `config/secrets.yml` using a text editor:
|
71
|
+
|
72
|
+
```yaml
|
73
|
+
ohmysmtp_api_token: "TOKEN_GOES_HERE"
|
74
|
+
```
|
75
|
+
|
76
|
+
Set OhMySMTP as your mail delivery method in `config/application.rb`:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
config.action_mailer.delivery_method = :ohmysmtp
|
80
|
+
config.action_mailer.ohmysmtp_settings = { :api_token => Rails.application.secrets.ohmysmtp_api_token }
|
81
|
+
```
|
82
|
+
|
83
|
+
## Support
|
84
|
+
|
85
|
+
For support please check the [OhMySMTP Documentation](https://docs.ohmysmtp.com) or contact us at support@ohmysmtp.com
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Pull requests always welcome
|
90
|
+
|
91
|
+
## License
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'OhMySMTP::Rails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
require 'httparty'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'ohmysmtp-rails/version'
|
6
|
+
require 'ohmysmtp-rails/railtie' if defined? Rails
|
7
|
+
|
8
|
+
module OhMySMTP
|
9
|
+
# OhMySMTP ActionMailer delivery method
|
10
|
+
class DeliveryMethod
|
11
|
+
attr_accessor :settings
|
12
|
+
|
13
|
+
def initialize(values)
|
14
|
+
check_api_token(values)
|
15
|
+
self.settings = {}.merge!(values)
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver!(mail)
|
19
|
+
check_delivery_params(mail)
|
20
|
+
result = HTTParty.post(
|
21
|
+
'https://app.ohmysmtp.com/api/v1/send',
|
22
|
+
body: {
|
23
|
+
from: mail.from.join(','),
|
24
|
+
to: mail.to.join(','),
|
25
|
+
subject: mail.subject,
|
26
|
+
htmlbody: mail.body,
|
27
|
+
cc: mail.cc&.join(','),
|
28
|
+
bcc: mail.bcc&.join(','),
|
29
|
+
replyto: mail.reply_to
|
30
|
+
}.to_json,
|
31
|
+
headers: {
|
32
|
+
'User-Agent' => "OhMySMTP Rails Gem v#{OhMySMTP::Rails::VERSION}",
|
33
|
+
'Accept' => 'application/json',
|
34
|
+
'Content-Type' => 'application/json',
|
35
|
+
'Ohmysmtp-Server-Token' => settings[:api_token]
|
36
|
+
}
|
37
|
+
)
|
38
|
+
|
39
|
+
handle_response(result)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def check_api_token(values)
|
45
|
+
return if values[:api_token].present?
|
46
|
+
|
47
|
+
raise ArgumentError, 'OhMySMTP API token is not set'
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_delivery_params(mail)
|
51
|
+
return unless mail.from.nil? || mail.to.nil?
|
52
|
+
|
53
|
+
raise ArgumentError, 'Missing to or from address in email'
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_response(result)
|
57
|
+
return unless result.code != 200
|
58
|
+
|
59
|
+
raise result['error']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ohmysmtp-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- OhMySMTP
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.2
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.2.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.2
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.2.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: actionmailer
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.0.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: httparty
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.18.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.18.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: byebug
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: pry
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sqlite3
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: The OhMySMTP Rails Gem is a plug in for ActionMailer to send emails via
|
104
|
+
OhMySMTP to make sending emails from Rails apps super simple.
|
105
|
+
email:
|
106
|
+
- support@ohmysmtp.com
|
107
|
+
executables: []
|
108
|
+
extensions: []
|
109
|
+
extra_rdoc_files: []
|
110
|
+
files:
|
111
|
+
- MIT-LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- lib/ohmysmtp-rails.rb
|
115
|
+
- lib/ohmysmtp-rails/railtie.rb
|
116
|
+
- lib/ohmysmtp-rails/version.rb
|
117
|
+
homepage: https://ohmysmtp.com
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.1.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Lets you send transactional emails from your app over an easy to use API
|
140
|
+
test_files: []
|