emailbutler 0.6.1 → 0.7.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: 70bf205c00cb4bf8907b43c549d763cee107e138e61bca507c130677726d7d86
4
- data.tar.gz: 9bd2eeb375ef2d02e0dff933586ac46093be662bafd3aa767a3441963678c6f7
3
+ metadata.gz: 612e4bc27184b6105020c585995ebb90cf6bc7f1d1d18cdd8833d22e762cc7c1
4
+ data.tar.gz: fc6c91f52ffdde4dba4585d685b7a5c4173793aa2c355d9593b2fcf852189781
5
5
  SHA512:
6
- metadata.gz: 7a694d31890e57a695aaf380c664a25a2cac922b3b89d6dc196e19a07b3119fb62eb72501999da5c2e2fd48365c43e8b26718d38907f5fa68394b83df53faee9
7
- data.tar.gz: 9100a4c42424bc8a6a1c1b1ef899dd3f02fef8f4c88592c958e1da0fb52e16d545e66ef0bc081551b62fe77c8a9f647bd3876036877cdf3e38ca0f68735c8a6f
6
+ metadata.gz: 9fb3f49d372b3bc87a0131913796bd0073d95a41521f53f351420223dbf14e0067d62d6e3f58b4bc9efee591736fc6e922d7e97d21aae4b373a32e92d446b317
7
+ data.tar.gz: a7930ffe63ac272075fe9af8bb1201b388bda1045c228815cb26ad64885c1189bdf84a2d610addcbeaa0c5bb73d6e2187aea1cb375d1b3a2e8a3773f455a5816
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Emailbutler
2
2
  Simple email tracker for Ruby on Rails applications.
3
- Emailbutler allows you to track delivery status of emails sent by your app.
3
+ Emailbutler allows you to track delivery status of emails sent by your app through Sendgrid and/or SMTP2GO.
4
4
 
5
5
  There are situations when you need to check whether a certain letter or certain type of letters was successfully sent from the application, and through the UI of some providers you can try to find such a letter by the recipient or the subject of the letter, but sometimes it's not enough.
6
6
 
@@ -36,6 +36,7 @@ Emailbutler.configure do |config|
36
36
  config.ui_username = 'username'
37
37
  config.ui_password = 'password'
38
38
  config.ui_secured_environments = ['production']
39
+ config.skip_before_actions = %i[verify_authenticity_token]
39
40
  end
40
41
  ```
41
42
 
@@ -59,7 +60,7 @@ class SendgridController < ApplicationController
59
60
  ... you can add some logic here
60
61
 
61
62
  ::Emailbutler::Webhooks::Receiver.call(
62
- user_agent: ::Emailbutler::Webhooks::Receiver::SENDGRID_USER_AGENT,
63
+ user_agent: request.headers['HTTP_USER_AGENT'],
63
64
  payload: receiver_params.to_h
64
65
  )
65
66
 
@@ -69,7 +70,10 @@ class SendgridController < ApplicationController
69
70
  private
70
71
 
71
72
  def receiver_params
72
- params.permit('_json' => %w[smtp-id event timestamp sg_message_id])
73
+ params.permit(
74
+ 'event', 'sendtime', 'message-id',
75
+ '_json' => %w[event timestamp smtp-id sg_message_id]
76
+ )
73
77
  end
74
78
  end
75
79
  ```
@@ -106,6 +110,14 @@ end
106
110
  - select all deliverability data,
107
111
  - save settings.
108
112
 
113
+ #### SMTP2GO
114
+
115
+ - go to [Mail settings](https://app-eu.smtp2go.com/settings/webhooks),
116
+ - turn on Webhooks,
117
+ - in the HTTP POST URL field, paste the URL to webhook controller of your app,
118
+ - select all deliverability data,
119
+ - save settings.
120
+
109
121
  ## Usage
110
122
 
111
123
  1. Each event with sending email will create new record with message params in database.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Emailbutler
4
4
  class WebhooksController < Emailbutler::ApplicationController
5
- skip_before_action :verify_authenticity_token
5
+ skip_before_action(*Emailbutler.configuration.skip_before_actions)
6
6
 
7
7
  def create
8
8
  ::Emailbutler::Webhooks::Receiver.call(
@@ -16,7 +16,10 @@ module Emailbutler
16
16
  private
17
17
 
18
18
  def receiver_params
19
- params.permit('_json' => %w[smtp-id event timestamp sg_message_id])
19
+ params.permit(
20
+ 'event', 'sendtime', 'message-id',
21
+ '_json' => %w[event timestamp smtp-id sg_message_id]
22
+ )
20
23
  end
21
24
  end
22
25
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Emailbutler
4
4
  class Configuration
5
- attr_accessor :adapter, :ui_username, :ui_password, :ui_secured_environments
5
+ attr_accessor :adapter, :ui_username, :ui_password, :ui_secured_environments, :skip_before_actions
6
6
 
7
7
  def initialize
8
8
  @adapter = nil
@@ -10,9 +10,11 @@ module Emailbutler
10
10
  # It's required to specify these 3 variables to enable basic auth to UI
11
11
  @ui_username = ''
12
12
  @ui_password = ''
13
-
14
13
  # Secured environments variable must directly contains environment names
15
14
  @ui_secured_environments = []
15
+
16
+ # Skip before_actions from your ApplicationController
17
+ @skip_before_actions = %i[verify_authenticity_token]
16
18
  end
17
19
  end
18
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emailbutler
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Emailbutler
4
+ module Webhooks
5
+ module Mappers
6
+ class Smtp2Go
7
+ DELIVERABILITY_MAPPER = {
8
+ 'processed' => 'processed',
9
+ 'delivered' => 'delivered',
10
+ 'open' => 'delivered',
11
+ 'click' => 'delivered',
12
+ 'bounce' => 'failed',
13
+ 'reject' => 'failed',
14
+ 'spam' => 'failed'
15
+ }.freeze
16
+
17
+ def self.call(...)
18
+ new.call(...)
19
+ end
20
+
21
+ def call(payload:)
22
+ payload.stringify_keys!
23
+ message_uuid = payload['message-id']
24
+ status = DELIVERABILITY_MAPPER[payload['event']]
25
+ return [] if message_uuid.nil? || status.nil?
26
+
27
+ [
28
+ {
29
+ message_uuid: message_uuid,
30
+ status: status,
31
+ timestamp: payload['sendtime'] ? Time.at(payload['sendtime'].to_i).utc.to_datetime : nil
32
+ }
33
+ ]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,18 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'emailbutler/webhooks/mappers/sendgrid'
4
+ require 'emailbutler/webhooks/mappers/smtp2go'
4
5
 
5
6
  module Emailbutler
6
7
  module Webhooks
7
8
  class Receiver
8
9
  SENDGRID_USER_AGENT = 'SendGrid Event API'
10
+ SMTP2GO_USER_AGENT = 'Go-http-client/1.1'
11
+
12
+ RECEIVERS_MAPPER = {
13
+ 'SendGrid Event API' => Emailbutler::Webhooks::Mappers::Sendgrid,
14
+ 'Go-http-client/1.1' => Emailbutler::Webhooks::Mappers::Smtp2Go
15
+ }.freeze
9
16
 
10
17
  def self.call(...)
11
18
  new.call(...)
12
19
  end
13
20
 
14
21
  def call(user_agent:, payload:)
15
- select_mapper(user_agent)
22
+ mapper = RECEIVERS_MAPPER[user_agent]
23
+ return unless mapper
24
+
25
+ mapper
16
26
  .call(payload: payload)
17
27
  .each { |event|
18
28
  message = Emailbutler.find_message_by(uuid: event.delete(:message_uuid))
@@ -21,14 +31,6 @@ module Emailbutler
21
31
  Emailbutler.update_message(message, event)
22
32
  }
23
33
  end
24
-
25
- private
26
-
27
- def select_mapper(user_agent)
28
- case user_agent
29
- when SENDGRID_USER_AGENT then Emailbutler::Webhooks::Mappers::Sendgrid
30
- end
31
- end
32
34
  end
33
35
  end
34
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emailbutler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pagy
@@ -202,6 +202,7 @@ files:
202
202
  - lib/emailbutler/mailers/helpers.rb
203
203
  - lib/emailbutler/version.rb
204
204
  - lib/emailbutler/webhooks/mappers/sendgrid.rb
205
+ - lib/emailbutler/webhooks/mappers/smtp2go.rb
205
206
  - lib/emailbutler/webhooks/receiver.rb
206
207
  - lib/generators/emailbutler/active_record_generator.rb
207
208
  - lib/generators/emailbutler/templates/migration.erb