Class: Bible270::NoticeMailer
- Inherits:
-
ApplicationMailer
- Object
- ActionMailer::Base
- ApplicationMailer
- Bible270::NoticeMailer
- Defined in:
- app/mailers/bible270/notice_mailer.rb
Overview
Transactional mail for readers and notices for whoever runs the plan.
Instance Method Summary collapse
-
#broadcast(reader_id:, subject:, body:) ⇒ Object
A message from whoever runs the plan to one reader.
- #daily_reminder(reader_id:, day:, on: Bible270.today) ⇒ Object
- #mentioned(comment_id:, reader_id:) ⇒ Object
- #new_reader(reader_id:, recipients:) ⇒ Object
Instance Method Details
#broadcast(reader_id:, subject:, body:) ⇒ Object
A message from whoever runs the plan to one reader. Sent individually rather than as one email with everyone in bcc: a bcc list of a hundred addresses is a spam signal, and it means nobody can be greeted by name or unsubscribe meaningfully.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/mailers/bible270/notice_mailer.rb', line 55 def broadcast(reader_id:, subject:, body:) @reader = Reader.find_by(id: reader_id) return .perform_deliveries = false if @reader.nil? || @reader.email.blank? return .perform_deliveries = false if subject.to_s.strip.empty? || body.to_s.strip.empty? @body = body.to_s @app_name = Bible270.config.app_name @plan_url = plan_url mail to: @reader.email, subject: subject.to_s.strip end |
#daily_reminder(reader_id:, day:, on: Bible270.today) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/mailers/bible270/notice_mailer.rb', line 34 def daily_reminder(reader_id:, day:, on: Bible270.today) @reader = Reader.find_by(id: reader_id) return .perform_deliveries = false unless Bible270.config.daily_reminders? return .perform_deliveries = false if @reader.nil? || !@reader.daily_reminders? || @reader.email.blank? @day = day.to_i @on = Plan.to_date(on) return .perform_deliveries = false unless Plan.valid_day?(@day) && @on @readings = Plan.readings_for(@day).select { |_, reference| reference } @app_name = Bible270.config.app_name @day_url = day_url_for(@day) @profile_url = profile_url mail to: @reader.email, subject: "#{@app_name}: day #{@day} reading reminder" end |
#mentioned(comment_id:, reader_id:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/mailers/bible270/notice_mailer.rb', line 21 def mentioned(comment_id:, reader_id:) @comment = Comment.find_by(id: comment_id) @reader = Reader.find_by(id: reader_id) return .perform_deliveries = false if @comment.nil? || @reader.nil? || @reader.email.blank? @author = @comment.reader @app_name = Bible270.config.app_name @day_url = day_url_for(@comment.day) mail to: @reader.email, subject: "#{@app_name}: #{@author.display_name} mentioned you on day #{@comment.day}" end |
#new_reader(reader_id:, recipients:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/mailers/bible270/notice_mailer.rb', line 6 def new_reader(reader_id:, recipients:) @reader = Reader.find_by(id: reader_id) # Blanks dropped rather than trusting the caller: [''] is not blank — a # one-element array never is — so it would otherwise have been sent to an # empty address, which fails at the SMTP server rather than here. addresses = Array(recipients).map { |address| address.to_s.strip }.reject(&:empty?) return .perform_deliveries = false if @reader.nil? || addresses.empty? @app_name = Bible270.config.app_name @total = Reader.count @admin_url = admin_url_for(@reader) mail to: addresses, subject: "#{@app_name}: #{@reader.display_name} has joined" end |