From e363602bea756ca022f73d6d6f23274c1490de75 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 07:11:03 -0500 Subject: [PATCH] Send reminders even when Redmine's email delivery is off Redmine sets perform_deliveries = false for every mailer when it has no email settings of its own, so reminders were skipped (and recorded as sent) without ever reaching the SMTP server. Messages sent through the plugin's own SMTP server now always go out; with Redmine's email settings, a reminder fails with a clear error instead of being dropped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- README.md | 2 +- app/mailers/appointment_reminder_mailer.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed09ff0..99bee9b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Then in the plugin's settings: SMTP server `smtp-relay.gmail.com`, port `587`, d App passwords: the mailbox needs 2-Step Verification; then Google Account » Security » **App passwords**. Google no longer accepts the account's regular password over SMTP. -Or choose **Redmine's email settings** to send through whatever `config/configuration.yml` uses. +Or choose **Redmine's email settings** to send through whatever `config/configuration.yml` uses. Redmine turns email delivery off when that file has no `email_delivery` section; reminders sent through the plugin's own SMTP server go out regardless, while with Redmine's settings the reminder fails with a message saying delivery is off. The password is kept in Redmine's plugin settings (in the database), like other plugin settings, and is visible to administrators on the settings page. diff --git a/app/mailers/appointment_reminder_mailer.rb b/app/mailers/appointment_reminder_mailer.rb index ee5adb8..b0c1136 100644 --- a/app/mailers/appointment_reminder_mailer.rb +++ b/app/mailers/appointment_reminder_mailer.rb @@ -26,11 +26,25 @@ class AppointmentReminderMailer < ActionMailer::Base # A Message-ID on the sending domain, rather than the server's host name headers['Message-ID'] = "" + delivery = settings.delivery_options + # Through Redmine's own settings, Redmine decides whether mail goes out at all; say so rather than + # quietly dropping the reminder + if delivery.empty? && !ActionMailer::Base.perform_deliveries + raise DeliveryOff, "Redmine's email delivery is turned off (config/configuration.yml); choose \"This SMTP server\" in the reminder settings" + end + options = { to: email, from: settings.from, subject: message.subject } options[:reply_to] = settings.reply_to if settings.reply_to - mail(options.merge(settings.delivery_options)) do |format| + mail(options.merge(delivery)) do |format| format.text { render plain: message.text } format.html { render html: message.html.html_safe } end + # Redmine turns delivery off for every mailer when it has no email settings of its own (and in some + # environments); reminders sent through the plugin's own SMTP server go out regardless + message_obj = self.message + message_obj.perform_deliveries = true unless delivery.empty? + message_obj end + + class DeliveryOff < StandardError; end end