I am using ActionMailer to send mails. I want to send mails to multiple recipients which I get from a view. Here is the controller code.
def groupcorres user = User.find(session[:user_id]) address = Array.new lines = Array.new args = params[:id].to_s # params[:id] is an array of user screen name. ex: j_doe, d_john lines = args.split(",") for line in lines recipient = User.find_by_screen_name(line) email = recipient.email.to_s + "," address << email end if param_posted?(:message) @message = Message.new(params[:message]) if @message.valid? UserMailer.deliver_groupmess( :user => user, :recipient => address, :message => @message, :user_url => profile_for(user), :reply_url => url_for(:action => "correspond", :id => user.screen_name) ) flash[:notice] = "Email sent." redirect_to profile_for(user) end end
and in models/user_mailer.rb , I have
def groupmess(mail) subject mail[:message].subject from ' Test<do-not-reply@test.com>' recipients mail[:recipient] body mail end
This seems to work , but the recipients never receive any emails. Also I saw on the development log , that the"To" field on the email dump is missing. When I send the message to a single user , the "To" address is present.
I think that a string of comma separated email address ex: user1@xxx.com, user2@yyy.com for the recipient would work as it does for any email client.
Any ideas what's wrong, Thanks Meenal