postmail_ruby 0.1.1 → 0.1.2
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 +9 -9
- data/lib/postmail_ruby/configuration.rb +1 -1
- data/lib/postmail_ruby/delivery_method/http.rb +1 -1
- data/lib/postmail_ruby/delivery_method/smtp.rb +2 -2
- data/lib/postmail_ruby/railtie.rb +6 -6
- data/lib/postmail_ruby/version.rb +1 -1
- data/lib/postmail_ruby.rb +7 -7
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '082b38d7e9f806d253c50216bcbcfbf4403c3d310bb1bef277f99c2de62350c3'
|
4
|
+
data.tar.gz: 19957be43157502c87a60c2b8289c893a5633d8f415b3be41807c600fa9b0b62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f734c2ea0208d4cf30a2ba049d75f35ac07b61f85ffe6503d49d1a3b5e59c3dd3c400d2076bf19997f5efadcbe657a4a6cee567a7093865ef244f4dac2a48951
|
7
|
+
data.tar.gz: 274e9ceef04ab13495b31bb6ecf2872dbc600d3f02b3d17e19b07e686c516bd10fffdd473d050ae23ddd7be994dc8b63318bb7b7a8548b72f100f1c9ec28e5b8
|
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# PostmailRuby
|
2
2
|
|
3
|
-
|
3
|
+
PostmailRuby est une gem Ruby qui fournit un mécanisme flexible d’envoi d’e‑mails pour Ruby on Rails ou tout projet utilisant Action Mailer. La gem propose deux méthodes d’expédition : soit par **SMTP**, soit par une **API HTTP**. Tous les paramètres de connexion et le choix de la méthode d’envoi se pilotent via des variables d’environnement afin de simplifier la configuration lors du déploiement.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Dans votre `Gemfile`, ajoutez :
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "postmail_ruby",
|
10
|
+
gem "postmail_ruby", '~> 0.1.1'
|
11
11
|
```
|
12
12
|
|
13
13
|
Puis exécutez `bundle install` pour installer la gem.
|
14
14
|
|
15
15
|
## Utilisation dans Rails
|
16
16
|
|
17
|
-
|
17
|
+
PostmailRuby enregistre deux méthodes de livraison personnalisées pour Action Mailer : `:postmail_smtp` et `:postmail_api`. La gem est livrée avec un **Railtie** qui détecte Rails et configure automatiquement Action Mailer en fonction des variables d’environnement ci‑dessous. En pratique, il suffit de définir vos variables d’environnement et de vous assurer que la gem est chargée.
|
18
18
|
|
19
19
|
Si vous souhaitez configurer explicitement la gem (par exemple hors de Rails), vous pouvez appeler :
|
20
20
|
|
@@ -32,7 +32,7 @@ Toutes les options de configuration se font via des variables d’environnement,
|
|
32
32
|
| Variable | Description | Valeur par défaut |
|
33
33
|
|---------|-------------|------------------|
|
34
34
|
| `POSTMAIL_DELIVERY_METHOD` | Choix de la méthode d’envoi : `smtp` (envoi via serveur SMTP) ou `api` (envoi via appel HTTP). | `smtp` |
|
35
|
-
| `POSTMAIL_DISABLE_RAILS_SMTP` | Lorsque défini à `true`,
|
35
|
+
| `POSTMAIL_DISABLE_RAILS_SMTP` | Lorsque défini à `true`, PostmailRuby désactive les paramètres SMTP par défaut de Rails (`ActionMailer::Base.smtp_settings`) pour éviter des retours en arrière accidentels. Utiliser cette option est recommandé si vous envoyez exclusivement via l’API. | `false` |
|
36
36
|
| `POSTMAIL_API_ENDPOINT` | URL complète de l’endpoint HTTP pour l’envoi par API (par exemple `https://postal.exanora.com/api/v1/send/message`). Obligatoire si `POSTMAIL_DELIVERY_METHOD=api`. | – |
|
37
37
|
| `POSTMAIL_API_KEY` | Clé d’API utilisée pour authentifier les requêtes HTTP (envoyée dans l’en‑tête `X-Server-API-Key`). | – |
|
38
38
|
| `POSTMAIL_API_TIMEOUT` | Temps d’attente maximum en secondes lors de l’appel HTTP. | `10` |
|
@@ -42,7 +42,7 @@ Toutes les options de configuration se font via des variables d’environnement,
|
|
42
42
|
| `POSTMAIL_SMTP_PASSWORD` | Mot de passe pour l’authentification SMTP. | `nil` |
|
43
43
|
| `POSTMAIL_SMTP_AUTHENTICATION` | Type d’authentification SMTP : `plain`, `login` ou `cram_md5`. | `plain` |
|
44
44
|
| `POSTMAIL_SMTP_ENABLE_STARTTLS_AUTO` | Active STARTTLS. Mettre `false` pour désactiver. | `true` |
|
45
|
-
| `POSTMAIL_SMTP_SSL` | Lorsque défini à `true`,
|
45
|
+
| `POSTMAIL_SMTP_SSL` | Lorsque défini à `true`, PostmailRuby établit une connexion SSL/TLS implicite (comme un port 465). | `false` |
|
46
46
|
| `POSTMAIL_SMTP_OPEN_TIMEOUT` | Durée maximale (en secondes) pour établir la connexion SMTP. | `30` |
|
47
47
|
| `POSTMAIL_SMTP_READ_TIMEOUT` | Durée maximale (en secondes) pour la lecture des réponses SMTP. | `30` |
|
48
48
|
|
@@ -54,7 +54,7 @@ Rails utilise un mécanisme SMTP par défaut si aucune méthode d’envoi n’es
|
|
54
54
|
POSTMAIL_DISABLE_RAILS_SMTP=true
|
55
55
|
```
|
56
56
|
|
57
|
-
Lorsque cette variable est à `true`,
|
57
|
+
Lorsque cette variable est à `true`, PostmailRuby réinitialise `ActionMailer::Base.smtp_settings` à un hash vide et définit `ActionMailer::Base.delivery_method` sur `:postmail_api` ou `:postmail_smtp` en fonction de `POSTMAIL_DELIVERY_METHOD`.
|
58
58
|
|
59
59
|
### Exemple de configuration
|
60
60
|
|
@@ -82,9 +82,9 @@ POSTMAIL_DISABLE_RAILS_SMTP=false
|
|
82
82
|
|
83
83
|
## Fonctionnement
|
84
84
|
|
85
|
-
Lorsque la méthode d’envoi est `api`,
|
85
|
+
Lorsque la méthode d’envoi est `api`, PostmailRuby sérialise votre message et l’envoie en `POST` vers l’endpoint HTTP. Le corps de la requête est JSON et inclut les adresses, le sujet, les corps texte/HTML et les pièces jointes (encodées en Base64). La clé API est transmise via l’en‑tête `X-Server-API-Key`.
|
86
86
|
|
87
|
-
Lorsque la méthode d’envoi est `smtp`,
|
87
|
+
Lorsque la méthode d’envoi est `smtp`, PostmailRuby utilise les paramètres SMTP renseignés pour établir la connexion avec le serveur de messagerie via la gem `mail`. Les options SSL/TLS, timeouts et authentification sont héritées des variables d’environnement.
|
88
88
|
|
89
89
|
## Contribuer
|
90
90
|
|
@@ -51,7 +51,7 @@ module PostmailRuby
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# Returns true if the default Rails SMTP configuration should be disabled.
|
54
|
-
# When this is true,
|
54
|
+
# When this is true, PostmailRuby will clear `config.action_mailer.smtp_settings`.
|
55
55
|
def disable_default_smtp?
|
56
56
|
@disable_default_smtp
|
57
57
|
end
|
@@ -5,10 +5,10 @@ require 'mail'
|
|
5
5
|
module PostmailRuby
|
6
6
|
module DeliveryMethod
|
7
7
|
# Provides a custom SMTP delivery method that reads its
|
8
|
-
# configuration from
|
8
|
+
# configuration from PostmailRuby::Configuration. This class is
|
9
9
|
# essentially a thin wrapper around Mail::SMTP, passing in
|
10
10
|
# settings derived from environment variables. It allows
|
11
|
-
# Action Mailer to use
|
11
|
+
# Action Mailer to use PostmailRuby configuration seamlessly.
|
12
12
|
class SMTP
|
13
13
|
attr_reader :settings
|
14
14
|
|
@@ -3,18 +3,18 @@
|
|
3
3
|
require 'rails/railtie'
|
4
4
|
|
5
5
|
module PostmailRuby
|
6
|
-
# Railtie for integrating
|
6
|
+
# Railtie for integrating PostmailRuby with Rails. This railtie
|
7
7
|
# registers custom delivery methods with Action Mailer and
|
8
|
-
# configures Action Mailer based on
|
8
|
+
# configures Action Mailer based on PostmailRuby configuration. It
|
9
9
|
# also offers an option to disable the default SMTP settings
|
10
|
-
# configured by Rails, allowing
|
10
|
+
# configured by Rails, allowing PostmailRuby to be the sole mail
|
11
11
|
# provider in a Rails application.
|
12
12
|
class Railtie < ::Rails::Railtie
|
13
13
|
initializer 'postmail_ruby.initialize' do
|
14
14
|
ActiveSupport.on_load(:action_mailer) do
|
15
15
|
# Register our delivery methods
|
16
|
-
ActionMailer::Base.add_delivery_method :postmail_smtp,
|
17
|
-
ActionMailer::Base.add_delivery_method :postmail_api,
|
16
|
+
ActionMailer::Base.add_delivery_method :postmail_smtp, PostmailRuby::DeliveryMethod::SMTP
|
17
|
+
ActionMailer::Base.add_delivery_method :postmail_api, PostmailRuby::DeliveryMethod::HTTP
|
18
18
|
|
19
19
|
# Determine which delivery method to use based on configuration
|
20
20
|
delivery_method = Postmail.config.delivery_method
|
@@ -28,7 +28,7 @@ module PostmailRuby
|
|
28
28
|
# If using SMTP, apply our SMTP settings and optionally
|
29
29
|
# clear any default Rails SMTP settings. The
|
30
30
|
# disable_default_smtp? flag removes Rails SMTP settings
|
31
|
-
# before applying
|
31
|
+
# before applying PostmailRuby settings.
|
32
32
|
if delivery_method == :smtp
|
33
33
|
if PostmailRuby.config.disable_default_smtp?
|
34
34
|
# Clear any pre-existing SMTP settings so they do not
|
data/lib/postmail_ruby.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'postmail_ruby/version'
|
4
4
|
require_relative 'postmail_ruby/configuration'
|
5
5
|
|
6
|
-
# Main entry point for the
|
6
|
+
# Main entry point for the PostmailRuby gem. This module exposes
|
7
7
|
# configuration and helper methods to integrate the gem into a
|
8
8
|
# Ruby on Rails application. When loaded in a Rails environment,
|
9
9
|
# a Railtie is required automatically to register custom delivery
|
@@ -15,7 +15,7 @@ module PostmailRuby
|
|
15
15
|
# object reads environment variables to determine how Postmail
|
16
16
|
# should behave (API vs SMTP, credentials, endpoints, etc.).
|
17
17
|
#
|
18
|
-
# @return [
|
18
|
+
# @return [PostmailRuby::Configuration]
|
19
19
|
attr_accessor :configuration
|
20
20
|
|
21
21
|
# Yields the configuration instance to a block so that callers
|
@@ -24,12 +24,12 @@ module PostmailRuby
|
|
24
24
|
# used to change settings in an initializer.
|
25
25
|
#
|
26
26
|
# @example Override the API endpoint
|
27
|
-
#
|
27
|
+
# PostmailRuby.configure do |config|
|
28
28
|
# config.api_endpoint = "https://my-postal.example/api/v1/send/message"
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
# @yieldparam [
|
32
|
-
# @return [
|
31
|
+
# @yieldparam [PostmailRuby::Configuration] configuration
|
32
|
+
# @return [PostmailRuby::Configuration]
|
33
33
|
def configure
|
34
34
|
self.configuration ||= Configuration.new
|
35
35
|
return configuration unless block_given?
|
@@ -43,7 +43,7 @@ module PostmailRuby
|
|
43
43
|
# created. This method should be used internally when a
|
44
44
|
# configuration is required.
|
45
45
|
#
|
46
|
-
# @return [
|
46
|
+
# @return [PostmailRuby::Configuration]
|
47
47
|
def config
|
48
48
|
self.configuration ||= Configuration.new
|
49
49
|
end
|
@@ -51,7 +51,7 @@ module PostmailRuby
|
|
51
51
|
end
|
52
52
|
|
53
53
|
# Require delivery method classes. These require statements are
|
54
|
-
# placed outside of the
|
54
|
+
# placed outside of the PostmailRuby module definition so that they
|
55
55
|
# are loaded when the gem is required. They rely on Postmail
|
56
56
|
# configuration, so configuration must be loaded first.
|
57
57
|
require_relative 'postmail_ruby/delivery_method/http'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postmail_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DAKIN Judicaël
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.7'
|
27
|
-
description:
|
28
|
-
allowing you to send email via either SMTP or an HTTP API. The delivery
|
29
|
-
all settings are configurable via environment variables so it can be
|
30
|
-
at runtime without code changes.
|
27
|
+
description: PostmailRuby is a simple gem that adds custom Action Mailer delivery
|
28
|
+
methods allowing you to send email via either SMTP or an HTTP API. The delivery
|
29
|
+
method and all settings are configurable via environment variables so it can be
|
30
|
+
easily switched at runtime without code changes.
|
31
31
|
email:
|
32
32
|
- d.j.bidossessi@gmail.com
|
33
33
|
executables: []
|