ohmysmtp-rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a597f7e583471f790c1e7b669ad4e9b5f1327675cc176f28016eab512cb0c7dc
4
- data.tar.gz: 631b23bdb932677707e24ddc4009c708843702d0ec2f44fc9b658c1beaccca2c
3
+ metadata.gz: d470ef101954142756a1fbfbf887b46bb526d22aab8db583b05e4b29be70a42a
4
+ data.tar.gz: feb8b35eae261cd5e7277bba69a1092b6ed9d02036aee20a988f8a2a81908ff2
5
5
  SHA512:
6
- metadata.gz: 908d2acb45d4b64fe17b2091da1b9289dd614f7c6d4f4a61698f17c39fab396a123994932e1281720a993a6a430b73baec18eec654bcfdb639a046f6bf22c63a
7
- data.tar.gz: 9cf4965645ce0f8d51320d8441516b311a5d833b8257159c1cd19d003a22a993a025056712dc02cb29b088c234ba73022ef86297766ed2e450c0e6cf13e390ad
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
- ## Usage
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
- Once installed and configured, continue to send emails using [ActionMailer](https://guides.rubyonrails.org/action_mailer_basics.html) like normal.
13
+ ## Usage
14
14
 
15
- ## Requirements
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 = 'OhMySMTP::Rails'
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,4 @@
1
+ Rails.application.routes.draw do
2
+ post 'rails/action_mailbox/ohmysmtp/inbound_emails', to: 'action_mailbox/ingresses/ohmysmtp/inbound_emails#create',
3
+ as: 'rails_ohmysmtp_inbound_emails'
4
+ end
@@ -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
@@ -1,5 +1,5 @@
1
- module OhMySMTP
1
+ module Ohmysmtp
2
2
  module Rails
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -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/railtie' if defined? Rails
7
+ require 'ohmysmtp-rails/engine' if defined? Rails
7
8
 
8
- module OhMySMTP
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#{OhMySMTP::Rails::VERSION}",
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.2.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-02 00:00:00.000000000 Z
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: 3.0.0
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: 3.0.0
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/railtie.rb
83
+ - lib/ohmysmtp-rails/engine.rb
82
84
  - lib/ohmysmtp-rails/version.rb
83
85
  homepage: https://ohmysmtp.com
84
86
  licenses:
@@ -1,7 +0,0 @@
1
- module OhMySMTP
2
- class Railtie < ::Rails::Railtie
3
- initializer 'ohmysmtp.add_delivery_method', before: 'action_mailer.set_configs' do
4
- ActionMailer::Base.add_delivery_method(:ohmysmtp, OhMySMTP::DeliveryMethod)
5
- end
6
- end
7
- end