Skip to content

Instantly share code, notes, and snippets.

@mankind
Forked from ashikajith/mailer_report_doc.md
Created August 9, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mankind/408a8b247952787c86be910d2415fd22 to your computer and use it in GitHub Desktop.
Save mankind/408a8b247952787c86be910d2415fd22 to your computer and use it in GitHub Desktop.
Mailer Report Doc

Mailer Report

For the mailer report we have WorkReportMailer which acts as the controller of the Application Mailer. The mailer is called in the ExportController file.

  def send_mail_report
    emails = process_email
    emails.each do |email|
      WorkReportMailer.send_report(email.strip, current_account.cname, params[:email_type]).deliver_later
    end
    redirect_to hyrax.admin_stats_path(anchor: 'email_reports')
  end

The following line will trigger the email via sidekiq, if we want to check the mail without sidekiq, replace deliver_later with deliver_now!

WorkReportMailer.send_report(email.strip, current_account.cname, params[:email_type]).deliver_later

The fetching of data and processing the values as per the report format is as follows.

  • We use ReportMailer service app/services/ubiquity/report_mailer.rb to query the records based on the email_type and process the data by sorting the records based on Work Type
  • The method for sorting the data is inside the services dir app/services/ubiquity/fetch_mailer_report_data.rb

To generate the mail preview we have a dedicated url to generate it. ' http://ashik.localhost:3000/rails/mailers/work_report_mailer/send_report

Please make sure you have the below ENV variable to enable this feature.

   # LocalEnv.yml
   ENABLE_MAILER_PREVIEWS: 'true'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment