ohmysmtp-rails 0.1.7 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d81c552bc6b41a27224f899c30770f06d4ec43fde051d597131fe88271d567f9
4
- data.tar.gz: cebbc8aa094bd151f7ede8063c64ab95dcad6415b0e55da537c804ee8c275ff4
3
+ metadata.gz: d470ef101954142756a1fbfbf887b46bb526d22aab8db583b05e4b29be70a42a
4
+ data.tar.gz: feb8b35eae261cd5e7277bba69a1092b6ed9d02036aee20a988f8a2a81908ff2
5
5
  SHA512:
6
- metadata.gz: 83e7282255476746b6d1d02656bc4a38b707bf44970c8673781e692809c7418c31c80271b133462a685e94dc7c87b965c0fd730296c774fc9abb2af9d17a49de
7
- data.tar.gz: df445b4af0d0cb736867b95cce2e41b82789d4002f05f7af303be517f1f0cff5329b1e780d15bed1ea9b188afa82f1feb6cf354870c070c0dd40aec966f1e111
6
+ metadata.gz: fa90965f77cfce6966a90c1fa6d95cf8e7b79d3d0341738c494673c4f89fb420a9d5a9a82a94dcc05ace98cece53fc694c91a1eda707c7cb490721fc0cfaaf97
7
+ data.tar.gz: efb761fc6fa8e6ff72f3796dd9be725a18d07667480f6d3aeadd006e9095ab118eb9437415d7c7e1da8cf94c0d14aff4b90a4b203a2447f6765e4af4553371bc
data/README.md CHANGED
@@ -2,17 +2,19 @@
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
4
4
  [![Gem Version](https://badge.fury.io/rb/ohmysmtp-rails.svg)](https://badge.fury.io/rb/ohmysmtp-rails)
5
-
5
+ [![OhMySMTP Rails](https://circleci.com/gh/ohmysmtp/ohmysmtp-rails.svg?style=svg)](https://app.circleci.com/pipelines/github/ohmysmtp/ohmysmtp-rails)
6
6
 
7
7
  [OhMySMTP](https://ohmysmtp.com) lets you send transactional emails from your app over an easy to use API.
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
+
13
+ ## Usage
12
14
 
13
- Once installed and configured, continue to send emails using [ActionMailer](https://guides.rubyonrails.org/action_mailer_basics.html) like normal.
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.
14
16
 
15
- ## Requirements
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.
@@ -106,6 +91,48 @@ end
106
91
 
107
92
  Note that this should always be a string, even if using an array of multiple tags.
108
93
 
94
+ ## List-Unsubscribe
95
+
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`
134
+
135
+ That's it! Emails should start flowing into your app just like magic.
109
136
  ## Support
110
137
 
111
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.1.7'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -1,18 +1,19 @@
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
12
13
 
13
14
  def initialize(values)
14
15
  check_api_token(values)
15
- self.settings = {}.merge!(values)
16
+ self.settings = { return_response: true }.merge!(values)
16
17
  end
17
18
 
18
19
  def deliver!(mail)
@@ -20,19 +21,22 @@ module OhMySMTP
20
21
  result = HTTParty.post(
21
22
  'https://app.ohmysmtp.com/api/v1/send',
22
23
  body: {
23
- from: mail.from_address.to_s,
24
+ from: mail.header[:from]&.address_list&.addresses&.first.to_s,
24
25
  to: mail.to.join(','),
25
26
  subject: mail.subject,
26
27
  htmlbody: mail.html_part ? mail.html_part.body.decoded : mail.body.to_s,
27
- textbody: mail.multipart? ? (mail.text_part ? mail.text_part.body.decoded : nil) : nil,
28
+ textbody: if mail.multipart?
29
+ mail.text_part ? mail.text_part.body.decoded : nil
30
+ end,
28
31
  cc: mail.cc&.join(','),
29
32
  bcc: mail.bcc&.join(','),
30
33
  replyto: mail.reply_to,
34
+ list_unsubscribe: mail.header['list_unsubscribe'].to_s,
31
35
  attachments: format_attachments(mail.attachments),
32
36
  tags: mail.header['tags'].to_s
33
- }.compact_blank.to_json,
37
+ }.delete_if { |_key, value| value.blank? }.to_json,
34
38
  headers: {
35
- 'User-Agent' => "OhMySMTP Rails Gem v#{OhMySMTP::Rails::VERSION}",
39
+ 'User-Agent' => "OhMySMTP Rails Gem v#{Ohmysmtp::Rails::VERSION}",
36
40
  'Accept' => 'application/json',
37
41
  'Content-Type' => 'application/json',
38
42
  'Ohmysmtp-Server-Token' => settings[:api_token]
@@ -57,7 +61,7 @@ module OhMySMTP
57
61
  end
58
62
 
59
63
  def handle_response(result)
60
- return unless result.code != 200
64
+ return result unless result.code != 200
61
65
 
62
66
  # TODO: Improved error handling
63
67
  res = result.parsed_response
@@ -75,4 +79,10 @@ module OhMySMTP
75
79
  end
76
80
  end
77
81
  end
82
+
83
+ class Error < StandardError; end
84
+
85
+ def self.root
86
+ Pathname.new(File.expand_path(File.join(__dir__, '..')))
87
+ end
78
88
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohmysmtp-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
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-04-06 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
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: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: actionmailer
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 3.0.0
19
+ version: 6.0.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 3.0.0
26
+ version: 6.0.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: httparty
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +39,33 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: 0.18.1
55
41
  - !ruby/object:Gem::Dependency
56
- name: byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
42
+ name: rails
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
45
  - - ">="
74
46
  - !ruby/object:Gem::Version
75
- version: '0'
47
+ version: 6.1.4.1
76
48
  type: :development
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
52
  - - ">="
81
53
  - !ruby/object:Gem::Version
82
- version: '0'
54
+ version: 6.1.4.1
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: sqlite3
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
88
60
  - !ruby/object:Gem::Version
89
- version: '0'
61
+ version: 1.4.2
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
66
  - - ">="
95
67
  - !ruby/object:Gem::Version
96
- version: '0'
68
+ version: 1.4.2
97
69
  description: The OhMySMTP Rails Gem is a plug in for ActionMailer to send emails via
98
70
  OhMySMTP to make sending emails from Rails apps super simple.
99
71
  email:
@@ -105,8 +77,10 @@ files:
105
77
  - MIT-LICENSE
106
78
  - README.md
107
79
  - Rakefile
80
+ - app/controllers/action_mailbox/ingresses/ohmysmtp/inbound_emails_controller.rb
81
+ - config/routes.rb
108
82
  - lib/ohmysmtp-rails.rb
109
- - lib/ohmysmtp-rails/railtie.rb
83
+ - lib/ohmysmtp-rails/engine.rb
110
84
  - lib/ohmysmtp-rails/version.rb
111
85
  homepage: https://ohmysmtp.com
112
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