thecore_backend_commons 3.2.10 → 3.2.11
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fe73ef2835e94090bd037724805658c43bb87820a68d2fc86eadd35747ef8e94
|
|
4
|
+
data.tar.gz: 707da7e03c6f3bad7499c95fa8616e0f43ff75feed46ebe0159ec05a0594f06f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 047fff2d4b57e67c7320df0e8d38874603084e91cab99d8e5802807bcf903f75c503360fa5e4845692876906db4118f720457f631c9a51cfbaf65099ed0a8a39
|
|
7
|
+
data.tar.gz: 10d926f3d871d4adb4ce2cc7a721b930d32a608ceb2505fc37e07f1408c0a96fe7f7e1d23c065a55e35d344d3433e2dc4fc1c7cb2778e5550079eeea56031ce4
|
data/README.md
CHANGED
|
@@ -55,12 +55,20 @@ ThecoreBackendCommons::SmtpConfig.setting(:from)
|
|
|
55
55
|
|
|
56
56
|
### Testare la configurazione SMTP
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Il gem espone `ThecoreBackendCommons::SmtpTester` e un rake task, disponibili automaticamente in qualsiasi app che include questo gem.
|
|
59
|
+
|
|
60
|
+
**Da rake task (shell):**
|
|
59
61
|
|
|
60
62
|
```bash
|
|
61
|
-
|
|
63
|
+
rails thecore_backend_commons:smtp:test[destinatario@example.com]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Da Rails console:**
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
ThecoreBackendCommons::SmtpTester.call("destinatario@example.com")
|
|
62
70
|
```
|
|
63
71
|
|
|
64
|
-
Se non si passa un indirizzo,
|
|
72
|
+
Se non si passa un indirizzo, in entrambi i casi viene usato `ThecoreSettings mytask.default_email`.
|
|
65
73
|
|
|
66
|
-
Lo
|
|
74
|
+
Lo tester stampa i parametri SMTP effettivamente usati (inclusi `tls` e `enable_starttls_auto`) prima di tentare la consegna. Restituisce `true`/`false` dal console e exit code `1` dal rake task in caso di errore.
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
namespace :thecore_backend_commons do
|
|
2
|
+
namespace :smtp do
|
|
3
|
+
desc "Send a test email using ThecoreSettings SMTP config. " \
|
|
4
|
+
"Usage: rails thecore_backend_commons:smtp:test[recipient@example.com] " \
|
|
5
|
+
"(omit argument to use mytask.default_email)"
|
|
6
|
+
task :test, [:recipient] => :environment do |_t, args|
|
|
7
|
+
success = ThecoreBackendCommons::SmtpTester.call(args[:recipient])
|
|
8
|
+
exit 1 unless success
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ThecoreBackendCommons
|
|
4
|
+
# Sends a test email using the SMTP settings from ThecoreSettings.
|
|
5
|
+
# Usable from the Rails console or via the rake task.
|
|
6
|
+
#
|
|
7
|
+
# From rails console:
|
|
8
|
+
# ThecoreBackendCommons::SmtpTester.call("you@example.com")
|
|
9
|
+
#
|
|
10
|
+
# From the shell:
|
|
11
|
+
# rails thecore_backend_commons:smtp:test[you@example.com]
|
|
12
|
+
class SmtpTester
|
|
13
|
+
def self.call(recipient = nil)
|
|
14
|
+
new(recipient).call
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize(recipient = nil)
|
|
18
|
+
@recipient = recipient.presence ||
|
|
19
|
+
ThecoreSettings::Setting.find_by(ns: :mytask, key: :default_email)&.raw
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def call
|
|
23
|
+
validate!
|
|
24
|
+
print_settings
|
|
25
|
+
send_mail
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def validate!
|
|
31
|
+
raise ArgumentError, "No recipient given and mytask.default_email is not configured." if @recipient.blank?
|
|
32
|
+
raise ArgumentError, "smtp.address is not configured in ThecoreSettings." if opts[:address].blank?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def print_settings
|
|
36
|
+
puts "SMTP settings:"
|
|
37
|
+
puts " address: #{opts[:address]}"
|
|
38
|
+
puts " port: #{opts[:port]}"
|
|
39
|
+
puts " domain: #{opts[:domain].inspect}"
|
|
40
|
+
puts " user_name: #{opts[:user_name].inspect}"
|
|
41
|
+
puts " authentication: #{opts[:authentication].inspect}"
|
|
42
|
+
puts " tls: #{opts[:tls]}"
|
|
43
|
+
puts " enable_starttls_auto:#{opts[:enable_starttls_auto]}"
|
|
44
|
+
puts " from: #{SmtpConfig.setting(:from).inspect}"
|
|
45
|
+
puts ""
|
|
46
|
+
puts "Sending test email to: #{@recipient}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def send_mail
|
|
50
|
+
from_address = SmtpConfig.setting(:from).presence || "noreply@mytask.local"
|
|
51
|
+
delivery_opts = opts
|
|
52
|
+
|
|
53
|
+
mail = Mail.new do
|
|
54
|
+
from from_address
|
|
55
|
+
to delivery_opts[:address] # placeholder; overridden below
|
|
56
|
+
subject "[MyTask] SMTP test — #{Time.current.strftime('%Y-%m-%d %H:%M:%S %Z')}"
|
|
57
|
+
body "This is an automated SMTP connectivity test sent from MyTask.\n\n" \
|
|
58
|
+
"If you received this message, the SMTP configuration is working correctly.\n\n" \
|
|
59
|
+
"Settings used:\n" \
|
|
60
|
+
" address: #{delivery_opts[:address]}\n" \
|
|
61
|
+
" port: #{delivery_opts[:port]}\n" \
|
|
62
|
+
" tls: #{delivery_opts[:tls]}\n" \
|
|
63
|
+
" auth: #{delivery_opts[:authentication].inspect}"
|
|
64
|
+
end
|
|
65
|
+
mail.to = @recipient
|
|
66
|
+
mail.delivery_method(:smtp, delivery_opts)
|
|
67
|
+
mail.deliver!
|
|
68
|
+
puts "OK: email delivered successfully."
|
|
69
|
+
true
|
|
70
|
+
rescue StandardError => e
|
|
71
|
+
puts "ERROR: #{e.class}: #{e.message}"
|
|
72
|
+
false
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def opts
|
|
76
|
+
@opts ||= SmtpConfig.delivery_options
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thecore_backend_commons
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.2.
|
|
4
|
+
version: 3.2.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriele Tassoni
|
|
@@ -208,6 +208,7 @@ files:
|
|
|
208
208
|
- lib/thecore_backend_commons.rb
|
|
209
209
|
- lib/thecore_backend_commons/engine.rb
|
|
210
210
|
- lib/thecore_backend_commons/smtp_config.rb
|
|
211
|
+
- lib/thecore_backend_commons/smtp_tester.rb
|
|
211
212
|
- lib/thecore_backend_commons/version.rb
|
|
212
213
|
homepage: https://github.com/gabrieletassoni/thecore_backend_commons
|
|
213
214
|
licenses: []
|