Created
April 10, 2015 03:19
-
-
Save Joseworks/9ee28e5939e41d23cc91 to your computer and use it in GitHub Desktop.
Send batch emails on ActiveAdmin Rails 4.2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
You are very welcome, Pierre, i hope it helps.
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
This is a great idea. Will clone it and test to see how it works.
Thanks
Pierre