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