Hello,
I have to send mail to multiple recipients. My table is named people
and has
first_name,last_name, email1 , email2, email3 for each person. i have
put people in various mailinglist .For example first mailinglist where
first_name is john or say the second mailing list contains people of
british origin.etc
the relation between mailinglist and people is many to many.
params[:ml] gives me the id of the mailing list to which mail is to be
sent.
In the controller i have
def sendmail
@mailinglists=Mailinglist.find_all_by_id(params[:ml])
@mailinglists.each do |ml|
@people =
Person.find(:all,:include=>:mailinglists,:conditions=>[‘mailinglist_id=?’,"#{params[:ml]}"])
UserMailer.deliver_send_mail(@people)
end
end
In the mailer model which i have named as user_mailer i have
class UserMailer < ActionMailer::Base
def send_mail(people)
#----------------------------------------
recipients people.email1
this generates error undefined method email1
#---------------------------------------------------
from "[email protected]"
subject "Thank you This is a test"
body "This is a test"
end
end
The recipients people.email1 generates an error undefined method email1
.
If i use the same code for person instead of people i.e if i send mail
to only one person and pass person as a parameter as
def send_mail(person)
recipients person.email1
…
…
then it works fine but i am able to send an email to only one person.
Please tell me what am i doing wrong and how do i proceed.
Thank you.
Regards,
Ank