Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Joseworks
Created April 10, 2015 03:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Joseworks/9ee28e5939e41d23cc91 to your computer and use it in GitHub Desktop.
Save Joseworks/9ee28e5939e41d23cc91 to your computer and use it in GitHub Desktop.
Send batch emails on ActiveAdmin Rails 4.2.0
<!-- Contact batch email -->
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<div>Name: <%= @name %></div>
<br>
<div>Subject: <%= @subject %></div>
<br>
<div>Reply to: <%= @email %></div>
<br>
<div>Message: </div>
<br>
<div><p><%= @message %></p></div>
<br>
</body>
</html>
class ContactBatchMailer < ActionMailer::Base
default from: "your_address_to_reply_to@example.com"
def contact_batch_email(name, email, message, subject, recipient)
@message = message
@name = name
@email = email
@subject = subject
@recipient = recipient
mail(to: recipient, :reply_to => email, name: @name, subject: @subject)
end
end
batch_action :email, form: {subject: :text, message: :textarea}, confirm: "Please enter the subject and the message below", if: proc{ your_condition_here_to_make_this_resource_available } do |ids, inputs|
batch_action_collection.find(ids).each do |user|
ContactBatchMailer.contact_batch_email(user.first_name, 'your_address_to_reply_to@example.com', inputs[:message], inputs[:subject], user.email).deliver
end
redirect_to collection_path, notice: "The batch email has been sent to all the users you selected."
end
@chumzp
Copy link

chumzp commented Apr 11, 2015

This is a great idea. Will clone it and test to see how it works.
Thanks
Pierre

@Joseworks
Copy link
Author

You are very welcome, Pierre, i hope it helps.

@pawan-yadav
Copy link

Thanks @Joseworks, It helped me a lot and save my day!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment