As a noob to rails I am struggling with being able to send a mail
template (html) stored in my database to all the users on a mailing
list. I can use the emailer page to send the mail template to a single
email address, but I want to be able to put a button on the mailinglists
show page that sends the mail template to all the mailings in the
mailinglist. The code is below for the key sections I am using.
I have been trying to figure out a solution for 4 days now and still
cannot get anything working and am loosing the will to live!!
Please if anyone could help me on this one I would be very very
greatfull.
Regards,
David
emailer controller
class Admin::EmailerController < Admin::AdminController
def sendmail
email = params[:email]
recipient = email[“recipient”]
subject = email[“subject”]
message = email[“message”]
Emailer.deliver_contact(recipient, subject, message)
return if request.xhr?
render :text => ‘Message sent successfully’
end
#def index
# render :file => ‘app\views\admin\emailer\index.html.erb’
#end
end
emailer index.html.erb
Send Email
<% form_tag :action => “sendmail” do %>
Subject:
<%= text_field ‘email’, ‘subject’ %>
Recipient:
<%= text_field ‘email’, ‘recipient’ %>
Message
<%= text_area ‘email’, ‘message’ %>
<%= submit_tag “sendmail” %>
<% end %>
mailinglists show.html.erb - using the mail_template
Mail Template(s) in use:
<% for mail_template in @mailinglist_templates %>
<%= link_to “#{mail_template.name}”,
admin_mail_template_path(mail_template), :class => ‘websnapr’ %>
<%= link_to ‘Edit’, edit_admin_mail_template_path(mail_template) %>
<% end %>
Subscriber List
<% for mailing in @mailinglist_mailings %><%= mailing.email_address %>
<% end %>oh and here is my mailer model
class Admin::Emailer < ActionMailer::Base
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = ‘[email protected]’
@sent_on = sent_at
@content_type = “text/html”
@body[“title”] = ‘This is title’
@body[“email”] = ‘[email protected]’
@body[“message”] = message
@headers = {}
end
end