diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d8bd387 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,3 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' layout 'mailer' end diff --git a/app/mailers/custom_mailer.rb b/app/mailers/custom_mailer.rb new file mode 100644 index 0000000..732ef66 --- /dev/null +++ b/app/mailers/custom_mailer.rb @@ -0,0 +1,23 @@ +# A custom mailer that can be used from the Rails console for one-off emails +# today, and later connected from an admin panel mailing page. +# +# Assign any template variables you want to use: +# +# user = User.first +# +# Create the email body from a custom email template file: +# +# body = ERB.new(File.read('./tmp/mailer-1.txt.erb')).result binding +# +# Send email via Sidekiq: +# +# CustomMailer.with(user: u, subject: "Important announcement", body: body).custom_message.deliver_later +# +class CustomMailer < ApplicationMailer + def custom_message + @user = params[:user] + @subject = params[:subject] + @body = params[:body] + mail(to: @user.email, subject: @subject) + end +end diff --git a/app/views/custom_mailer/custom_message.text.erb b/app/views/custom_mailer/custom_message.text.erb new file mode 100644 index 0000000..31bd20e --- /dev/null +++ b/app/views/custom_mailer/custom_message.text.erb @@ -0,0 +1 @@ +<%= @body %> diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index cbd34d2..caaac55 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -2,9 +2,7 @@
- +