ohmysmtp-rails 0.2.0 → 0.3.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/README.md +45 -22
- data/Rakefile +1 -1
- data/app/controllers/action_mailbox/ingresses/ohmysmtp/inbound_emails_controller.rb +57 -0
- data/config/routes.rb +4 -0
- data/lib/ohmysmtp-rails/engine.rb +12 -0
- data/lib/ohmysmtp-rails/version.rb +2 -2
- data/lib/ohmysmtp-rails.rb +10 -3
- metadata +7 -5
- data/lib/ohmysmtp-rails/railtie.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d470ef101954142756a1fbfbf887b46bb526d22aab8db583b05e4b29be70a42a
|
4
|
+
data.tar.gz: feb8b35eae261cd5e7277bba69a1092b6ed9d02036aee20a988f8a2a81908ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa90965f77cfce6966a90c1fa6d95cf8e7b79d3d0341738c494673c4f89fb420a9d5a9a82a94dcc05ace98cece53fc694c91a1eda707c7cb490721fc0cfaaf97
|
7
|
+
data.tar.gz: efb761fc6fa8e6ff72f3796dd9be725a18d07667480f6d3aeadd006e9095ab118eb9437415d7c7e1da8cf94c0d14aff4b90a4b203a2447f6765e4af4553371bc
|
data/README.md
CHANGED
@@ -8,11 +8,13 @@
|
|
8
8
|
|
9
9
|
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.
|
10
10
|
|
11
|
-
|
11
|
+
> **New in 0.3.0: The ability to consume [inbound emails](https://docs.ohmysmtp.com/guide/inbound/) from OhMySMTP via ActionMailbox**
|
12
12
|
|
13
|
-
|
13
|
+
## Usage
|
14
14
|
|
15
|
-
|
15
|
+
Once installed and configured, continue to send emails using [ActionMailer](https://guides.rubyonrails.org/action_mailer_basics.html) and receive emails with [ActionMailbox](https://edgeguides.rubyonrails.org/action_mailbox_basics.html) like normal.
|
16
|
+
|
17
|
+
## Other Requirements
|
16
18
|
|
17
19
|
You will need an OhMySMTP account with a verified domain and organization with an active plan.
|
18
20
|
|
@@ -42,9 +44,7 @@ $ gem install ohmysmtp-rails
|
|
42
44
|
|
43
45
|
### Configure the Gem
|
44
46
|
|
45
|
-
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
|
46
|
-
|
47
|
-
#### Rails 6
|
47
|
+
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.
|
48
48
|
|
49
49
|
Use the encrypted secret management to save your API Token to `config/credentials.yml.enc` by running the following:
|
50
50
|
|
@@ -66,21 +66,6 @@ config.action_mailer.delivery_method = :ohmysmtp
|
|
66
66
|
config.action_mailer.ohmysmtp_settings = { api_token: Rails.application.credentials.ohmysmtp_api_token }
|
67
67
|
```
|
68
68
|
|
69
|
-
#### Rails 3-5
|
70
|
-
|
71
|
-
Save your API Token to `config/secrets.yml` using a text editor:
|
72
|
-
|
73
|
-
```yaml
|
74
|
-
ohmysmtp_api_token: "TOKEN_GOES_HERE"
|
75
|
-
```
|
76
|
-
|
77
|
-
Set OhMySMTP as your mail delivery method in `config/application.rb`:
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
config.action_mailer.delivery_method = :ohmysmtp
|
81
|
-
config.action_mailer.ohmysmtp_settings = { :api_token => Rails.application.secrets.ohmysmtp_api_token }
|
82
|
-
```
|
83
|
-
|
84
69
|
## Tagging
|
85
70
|
|
86
71
|
You can tag messages and filter them later in the OhMySMTP UI. To do this, pass the tags as a header by adding a tag variable to your `mail` method call.
|
@@ -108,8 +93,46 @@ Note that this should always be a string, even if using an array of multiple tag
|
|
108
93
|
|
109
94
|
## List-Unsubscribe
|
110
95
|
|
111
|
-
To add a List-Unsubscribe header:
|
96
|
+
To add a List-Unsubscribe header, pass a `list_unsubscribe` string to the `mail` function:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
class TestMailer < ApplicationMailer
|
100
|
+
default from: 'notifications@example.com',
|
101
|
+
to: 'fake@sdfasdfsdaf.com'
|
102
|
+
|
103
|
+
def list_unsub_header
|
104
|
+
mail(
|
105
|
+
list_unsubscribe: 'https://listunsublink.com'
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
## ActionMailbox (for receiving inbound emails)
|
112
|
+
|
113
|
+
As of v0.3.0, this Gem supports handling Inbound Emails (see https://docs.ohmysmtp.com/guide/inbound/ for more details) via ActionMailbox. To set this up:
|
114
|
+
|
115
|
+
1. Tell Action Mailbox to accept emails from OhMySMTP in `config/environments/production.rb`
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
config.action_mailbox.ingress = :ohmysmtp
|
119
|
+
```
|
120
|
+
|
121
|
+
2. Generate a strong password that Action Mailbox can use to authenticate requests to the OhMySMTP ingress.
|
122
|
+
Use `bin/rails credentials:edit` to add the password to your application's encrypted credentials under `action_mailbox.ingress_password`, where Action Mailbox will automatically find it:
|
123
|
+
|
124
|
+
```yaml
|
125
|
+
action_mailbox:
|
126
|
+
ingress_password: ...
|
127
|
+
```
|
128
|
+
|
129
|
+
Alternatively, provide the password in the `RAILS_INBOUND_EMAIL_PASSWORD` environment variable.
|
130
|
+
|
131
|
+
3. Configure OhMySMTP to forward inbound emails to `/rails/action_mailbox/ohmysmtp/inbound_emails` with the username `actionmailbox` and the password you previously generated. If your application lived at `https://example.com` you would configure your OhMySMTP inbound endpoint URL with the following fully-qualified URL:
|
132
|
+
|
133
|
+
`https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/ohmysmtp/inbound_emails`
|
112
134
|
|
135
|
+
That's it! Emails should start flowing into your app just like magic.
|
113
136
|
## Support
|
114
137
|
|
115
138
|
For support please check the [OhMySMTP Documentation](https://docs.ohmysmtp.com) or contact us at support@ohmysmtp.com
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ require 'rdoc/task'
|
|
8
8
|
|
9
9
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
10
|
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = '
|
11
|
+
rdoc.title = 'Ohmysmtp::Rails'
|
12
12
|
rdoc.options << '--line-numbers'
|
13
13
|
rdoc.rdoc_files.include('README.md')
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionMailbox
|
4
|
+
module Ingresses
|
5
|
+
module Ohmysmtp
|
6
|
+
# Ingests inbound emails from OhMySMTP. Uses the a +raw+ parameter containing the full RFC 822 message.
|
7
|
+
#
|
8
|
+
# Authenticates requests using HTTP basic access authentication. The username is always +actionmailbox+, and the
|
9
|
+
# password is read from the application's encrypted credentials or an environment variable. See the Usage section.
|
10
|
+
#
|
11
|
+
# Returns:
|
12
|
+
#
|
13
|
+
# - <tt>204 No Content</tt> if an inbound email is successfully recorded and enqueued for routing
|
14
|
+
# - <tt>401 Unauthorized</tt> if the request's signature could not be validated
|
15
|
+
# - <tt>404 Not Found</tt> if Action Mailbox is not configured to accept inbound emails from OhMySMTP
|
16
|
+
# - <tt>422 Unprocessable Entity</tt> if the request is missing the required +RawEmail+ parameter
|
17
|
+
# - <tt>500 Server Error</tt> if the ingress password is not configured, or if one of the Active Record database,
|
18
|
+
# the Active Storage service, or the Active Job backend is misconfigured or unavailable
|
19
|
+
#
|
20
|
+
# == Usage
|
21
|
+
#
|
22
|
+
# 1. Tell Action Mailbox to accept emails from OhMySMTP:
|
23
|
+
#
|
24
|
+
# # config/environments/production.rb
|
25
|
+
# config.action_mailbox.ingress = :ohmysmtp
|
26
|
+
#
|
27
|
+
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the OhMySMTP ingress.
|
28
|
+
#
|
29
|
+
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
|
30
|
+
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
|
31
|
+
#
|
32
|
+
# action_mailbox:
|
33
|
+
# ingress_password: ...
|
34
|
+
#
|
35
|
+
# Alternatively, provide the password in the +RAILS_INBOUND_EMAIL_PASSWORD+ environment variable.
|
36
|
+
#
|
37
|
+
# 3. {Configure OhMySMTP}[https://docs.ohmysmtp.com/guide/inbound] to forward inbound emails
|
38
|
+
# to +/rails/action_mailbox/ohmysmtp/inbound_emails+ with the username +actionmailbox+ and the password you
|
39
|
+
# previously generated. If your application lived at <tt>https://example.com</tt>, you would configure your
|
40
|
+
# OhMySMTP inbound endpoint URL with the following fully-qualified URL:
|
41
|
+
#
|
42
|
+
# https://actionmailbox:PASSWORD@example.com/rails/action_mailbox/ohmysmtp/inbound_emails
|
43
|
+
#
|
44
|
+
class InboundEmailsController < ActionMailbox::BaseController
|
45
|
+
before_action :authenticate_by_password
|
46
|
+
|
47
|
+
def create
|
48
|
+
ActionMailbox::InboundEmail.create_and_extract_message_id! params.require('raw')
|
49
|
+
rescue ActionController::ParameterMissing => e
|
50
|
+
logger.error e.message
|
51
|
+
|
52
|
+
head :unprocessable_entity
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ohmysmtp
|
4
|
+
# Provides the delivery method & sets up action mailbox
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
initializer 'ohmysmtp.add_delivery_method', before: 'action_mailer.set_configs' do
|
7
|
+
ActionMailer::Base.add_delivery_method(:ohmysmtp, Ohmysmtp::DeliveryMethod)
|
8
|
+
end
|
9
|
+
|
10
|
+
config.action_mailbox.ohmysmtp = ActiveSupport::OrderedOptions.new
|
11
|
+
end
|
12
|
+
end
|
data/lib/ohmysmtp-rails.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'action_mailer'
|
2
|
+
require 'action_mailbox/engine'
|
2
3
|
require 'httparty'
|
3
4
|
require 'uri'
|
4
5
|
require 'json'
|
5
6
|
require 'ohmysmtp-rails/version'
|
6
|
-
require 'ohmysmtp-rails/
|
7
|
+
require 'ohmysmtp-rails/engine' if defined? Rails
|
7
8
|
|
8
|
-
module
|
9
|
+
module Ohmysmtp
|
9
10
|
# OhMySMTP ActionMailer delivery method
|
10
11
|
class DeliveryMethod
|
11
12
|
attr_accessor :settings
|
@@ -35,7 +36,7 @@ module OhMySMTP
|
|
35
36
|
tags: mail.header['tags'].to_s
|
36
37
|
}.delete_if { |_key, value| value.blank? }.to_json,
|
37
38
|
headers: {
|
38
|
-
'User-Agent' => "OhMySMTP Rails Gem v#{
|
39
|
+
'User-Agent' => "OhMySMTP Rails Gem v#{Ohmysmtp::Rails::VERSION}",
|
39
40
|
'Accept' => 'application/json',
|
40
41
|
'Content-Type' => 'application/json',
|
41
42
|
'Ohmysmtp-Server-Token' => settings[:api_token]
|
@@ -78,4 +79,10 @@ module OhMySMTP
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
82
|
+
|
83
|
+
class Error < StandardError; end
|
84
|
+
|
85
|
+
def self.root
|
86
|
+
Pathname.new(File.expand_path(File.join(__dir__, '..')))
|
87
|
+
end
|
81
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohmysmtp-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OhMySMTP
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,8 +77,10 @@ files:
|
|
77
77
|
- MIT-LICENSE
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
+
- app/controllers/action_mailbox/ingresses/ohmysmtp/inbound_emails_controller.rb
|
81
|
+
- config/routes.rb
|
80
82
|
- lib/ohmysmtp-rails.rb
|
81
|
-
- lib/ohmysmtp-rails/
|
83
|
+
- lib/ohmysmtp-rails/engine.rb
|
82
84
|
- lib/ohmysmtp-rails/version.rb
|
83
85
|
homepage: https://ohmysmtp.com
|
84
86
|
licenses:
|