Forum: Ruby on Rails ActionMailer Multiple recipients

2c7b8b1b7711668a7e431a6befa574d7?d=identicon&s=25 Meenal (Guest)
on 2008-05-03 16:34
(Received via mailing list)
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-05-03 17:06
(Received via mailing list)
On 3 May 2008, at 15:33, Meenal wrote:

> 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
You don't need to add commas. that's probably messing everything up.

Fred
2c7b8b1b7711668a7e431a6befa574d7?d=identicon&s=25 Meenal (Guest)
on 2008-05-03 21:26
(Received via mailing list)
Thanks Fred, the commas were the problem.


On May 3, 10:06 am, Frederick Cheung <frederick.che...@gmail.com>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.