Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ismailmechbal/b2200f118b2934aabab0 to your computer and use it in GitHub Desktop.
Save ismailmechbal/b2200f118b2934aabab0 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment