@@ -18,17 +18,39 @@ def check
1818 end
1919end
2020
21+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
2122class CustomMailerCheck < OkComputer ::Check
23+ require 'net/smtp'
2224 # Check that the mail password is set
2325 def check
24- if ENV [ 'MAIL_PASSWORD' ] . present?
25- mark_message 'Environment variable MAIL_PASSWORD is set.'
26- else
26+ settings = ActionMailer ::Base . smtp_settings
27+ begin
28+ Net ::SMTP . start (
29+ settings [ :address ] ,
30+ settings [ :port ] ,
31+ settings [ :domain ] ,
32+ settings [ :user_name ] ,
33+ settings [ :password ] ,
34+ settings [ :authentication ] ,
35+ tls : true
36+ ) { mark_message 'Connection for smtp successful' }
37+ rescue Net ::SMTPAuthenticationError => e
2738 mark_failure
28- mark_message 'Environment variable MAIL_PASSWORD is not set!'
39+ mark_message "Authentication error: #{ e . message } "
40+ rescue Net ::SMTPServerBusy , Net ::SMTPSyntaxError , Net ::SMTPFatalError , Net ::SMTPUnknownError => e
41+ mark_failure
42+ mark_message "SMTP error: #{ e . message } "
43+ rescue IOError , Net ::ReadTimeout => e
44+ mark_failure
45+ mark_message "Connection error: #{ e . message } "
46+ rescue StandardError => e
47+ # Catch any other unexpected errors
48+ mark_failure
49+ mark_message "An unexpected error occurred: #{ e . message } "
2950 end
3051 end
3152end
53+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
3254
3355# Ensure Alma API is working.
3456OkComputer ::Registry . register 'alma-patron-lookup' , AlmaPatronCheck . new
0 commit comments