how to mask recipients addresses , action mailer 4 with bcc: or other

1.1k views Asked by At

I am using action mailer with an array of emails. Emails are sending out successfully but in the received email, everyone can see the other recipients. I want to hide them from each other.

There are many posts about this and I've tried many things without success. Would be great if someone can spot what I'm doing wrong. I'm using rails 4.1.7. with delayed_job and devise. I am sure this must be something easy i have missed. Thanks in advance for any help.

My mailer is :

def send_email(mymodel)
  @mymodel = mymodel
  emails = @mymodel.followers.collect(&:email) 
  @url  = 'http://example.com/'
  mail(:to => emails, :bcc => ["[email protected]"], subject:"myemailsubject")  
end
1

There are 1 answers

5
SHS On BEST ANSWER
mail(to: emails, bcc: ["[email protected]"], subject: "myemailsubject")

You could exchange the bcc value with the to value.

mail(to: ["[email protected]"], bcc: emails, subject: "myemailsubject")

That should send out only 1 email, yet achieve what you want. However the email recipients might be slightly confused if they read the to field and don't find their own email address.

You could try the following but obviously it'll send out multiple emails:

emails.each do |email|
  mail(to: email, bcc: ["[email protected]"], subject: "myemailsubject")
end