Reputation: 107
I'm using ruby to send transactional emails via Mandrill. As part of my product, I want to be able to send the same email to two recipients and have them see each other's email address. (Like an introduction mail between two people).
So I filled he "to" field with both emails, and on my dashboard is seems that both are sent. But unfortunately only one of the recipients receive the mail and the details of the second recipient is hidden.
In conclusion, I have two problems:
Only one recipient gets the mail
Hidden details of the second recipient.
Upvotes: 1
Views: 1151
Reputation: 107
I approached Mandrill support and this is what they replied:
If you'd like to enable this option globally for all of the messages you send, then you'll want to ensure that you have the "Expose The List Of Recipients When Sending To Multiple Addresses" option enabled in your Sending Defaults.
If, instead of making that change globally, you'd like to enable it for individual messages, you'll want to use the X-MC-PreserveRecipients (SMTP header), or the preserve_recipients (API parameter), and set it to 'true'.
If you set this option to true, we'll expose the list of recipients to each other as you would see happen when sending mail from a typical email client program.
It worked!
Upvotes: 3
Reputation: 410
If you want both recipients to be able to see each other, you can pass an array of e-mails in the to
option.
If you do not want either of them to see each other, you can, in a loop over the users, send said e-mail.
If using ActionMailer
it can be done like so:
mail(
to: ['[email protected]', '[email protected]']
)
Or in a loop:
[user1, user2].each do |user|
UserMailer.some_email(user).deliver_now
end
mail(
to: user.email
)
Post your code, I have an idea of what your problem may be. Remember that a method in an ActionMailer
class should only return mail()
and must not be looped over inside of that method.
tldr: do everything unrelated to e-mail outside mailer, pass through necessary data as params to the method, end method with mail()
call.
Upvotes: 1