sidemail-delivery 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a15089d3b51c6eb6062e698b08b1edb7e5e8afa39a951ee33cdbc11807be57ff
4
+ data.tar.gz: 01bd934d193bdcfd75f0bc89f69d02092b5891db1cb58cf54b389a3807609604
5
+ SHA512:
6
+ metadata.gz: e693160bc90839f2e74a420abc04cc819e3c4bd8ebdc910ac510e0688ab4e8a1137f0def9bcbc43b5bf18fce6c84781035c2794965081863ac3438f098242d4b
7
+ data.tar.gz: be243f15c94637c8ae78e65fd97324785bcb99f8d936d9d36a38f1f2d5940eff5044d3ba7fdac443b98885675b2e9491762880b7c7aeadfbf8d0866f04bb4ddb
data/CHANGELOG.md ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Frank Groeneveld
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,38 @@
1
+ # Sidemail::Delivery
2
+ A Rails delivery method that uses the [Sidemail](https://sidemail.io) transactional API for sending outgoing mail.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem "sidemail-delivery"
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Create an initializer in `config/initializers/sidemail_delivery.rb` to configure your Sidemail API key:
17
+
18
+ ```ruby
19
+ Sidemail::Delivery.configure do |config|
20
+ config.api_key = "YOUR_API_KEY"
21
+ end
22
+ ```
23
+
24
+ Now set your delivery method for your preferred environment, for example in `config/environments/production.rb`:
25
+
26
+ ```ruby
27
+ Rails.application.configure do
28
+ # ...
29
+ config.action_mailer.delivery_method = :sidemail
30
+ # ...
31
+ end
32
+ ```
33
+
34
+ Finally you might need to contact Sidemail support to enable HTML sending through their API.
35
+ They disable it by default to prevent abuse.
36
+
37
+ ## License
38
+ 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,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ module Sidemail
2
+ module Delivery
3
+ class Railtie < ::Rails::Railtie
4
+ initializer "sidemail_delivery.configure_rails_initialization" do
5
+ ActionMailer::Base.add_delivery_method :sidemail, Sidemail::Delivery::Method
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Sidemail
2
+ module Delivery
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ require "sidemail/delivery/version"
2
+ require "sidemail/delivery/railtie"
3
+
4
+ module Sidemail
5
+ module Delivery
6
+ class << self
7
+ attr_accessor :settings
8
+ end
9
+
10
+ def self.configure
11
+ self.settings ||= Settings.new
12
+ yield(settings)
13
+ end
14
+
15
+ class Settings
16
+ attr_accessor :api_key
17
+ end
18
+
19
+ class Exception < StandardError
20
+ end
21
+
22
+ class Method
23
+ URL = URI("https://api.sidemail.io/v1/email/send")
24
+
25
+ def initialize(_options)
26
+ # empty but unused, to avoid errors
27
+ end
28
+
29
+ def deliver!(mail)
30
+ payload = {
31
+ fromName: mail[:from].addrs.first.display_name,
32
+ fromAddress: mail[:from].addrs.first.address,
33
+ html: mail.html_part.decoded,
34
+ text: mail.text_part.decoded,
35
+ subject: mail[:subject]
36
+ }
37
+ if mail.attachments.size.positive?
38
+ payload[:attachments] = mail.attachments.map do |attachment|
39
+ {name: attachment.filename, content: Base64.strict_encode64(attachment.body.decoded)}
40
+ end
41
+ end
42
+
43
+ response = post_to_api(mail[:to].addrs.map(&:address), payload)
44
+
45
+ JSON.parse(response.body).tap do |json|
46
+ raise Sidemail::Delivery::Exception.new(json["errorCode"]) if json.key?("errorCode")
47
+ end
48
+ rescue JSON::ParserError
49
+ raise Sidemail::Delivery::Exception.new("Unable to parse response")
50
+ end
51
+
52
+ protected
53
+
54
+ def post_to_api(addresses, payload)
55
+ https = Net::HTTP.new(URL.host, URL.port)
56
+ https.use_ssl = true
57
+
58
+ request = Net::HTTP::Post.new(URL)
59
+ request["Content-Type"] = "application/json"
60
+ request["Authorization"] = "Bearer #{Sidemail::Delivery.settings.api_key}"
61
+ request.body = JSON.generate(addresses.map { |to| {toAddress: to}.merge(payload) })
62
+
63
+ https.request(request)
64
+ end
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidemail-delivery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Groeneveld
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-01 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.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.0.0
27
+ description: A Rails delivery method that uses the Sidemail transactional API for
28
+ sending outgoing mail.
29
+ email:
30
+ - frank@toolsfactory.nl
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - lib/sidemail/delivery.rb
40
+ - lib/sidemail/delivery/railtie.rb
41
+ - lib/sidemail/delivery/version.rb
42
+ homepage: https://github.com/toolsfactory-nl/sidemail_delivery
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/toolsfactory-nl/sidemail_delivery
47
+ source_code_uri: https://github.com/toolsfactory-nl/sidemail_delivery
48
+ changelog_uri: https://github.com/toolsfactory-nl/sidemail_delivery/blob/master/CHANGELOG.md
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.4.10
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Rails delivery method for Sidemail.
68
+ test_files: []