mirror of
https://github.com/rickbarrette/redmine_qbo_reminders.git
synced 2026-11-17 13:00:36 -05:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
2 files changed
+16
-2
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
@@ -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'] = "<reminder.#{Time.now.to_i}.#{SecureRandom.hex(6)}@#{settings.mail_domain}>"
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user