On 1 Dec 2008, at 10:54, Dave Smith wrote:
> > > 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. > Well instead of doing Emailer.deliver_contact(recipient, subject, message) You could clearly do recipients.each do |recipient| Emailer.deliver_contact(recipient, subject, message) end assuming that recipients was some collection of email addresses Fred > 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 > ----------------------------------------------------------------------- > > <h1>Send Email</h1> > > <% form_tag :action => "sendmail" do %> > <p> > <label for="email_subject">Subject</label>: > <%= text_field 'email', 'subject' %> > </p> > <p> > <label for="email_recipient">Recipient</label>: > <%= text_field 'email', 'recipient' %> > </p> > <p> > <label for="email_message">Message</label><br/> > <%= text_area 'email', 'message' %> > </p> > <%= submit_tag "sendmail" %> > <% end %> > ------------------------------------------------------------------------- > > mailinglists show.html.erb - using the mail_template > ------------------------------------------------------------------------- > <b>Mail Template(s) in use:</b> > <% 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 %> > </p> > <br/> > <hr> <h4><b>Subscriber List</b></h4> > <% for mailing in @mailinglist_mailings %> > <p><%= mailing.email_address %></p> > <% 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 > -- > Posted via http://www.ruby-forum.com/. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---