One of my favorite ways to send mail from Ruby is through the Pony gem. If you haven’t used it, it’s definitely worth a look. I recently found the need to send mail to multiple recipients, and I couldn’t figure out how based on their documentation.

With a little experimentation, I found that you can simply separate the recipients with a comma, like so:

Pony.mail ( :to => '[email protected],[email protected]' ) 

This works for the To field, as well as the CC and BCC fields. You can simplify this, especially when the recipients are obtained at run time, by using an array of recipients with the join method.

to_addresses = [
'[email protected]' ,
'[email protected]' ,
'[email protected]'
] [email protected]

cc_addresses = [
'[email protected]' ,
'[email protected]'
]

Pony.mail (
:to => to_addresses.join(',') ,
:cc => cc_addresses.join(',')
)

 

Update:

As Jeff points out below, you can actually use an array directly! That makes the above simpler:

to_addresses = [
'[email protected]' ,
'[email protected]' ,
'[email protected]'
] [email protected]

cc_addresses = [
'[email protected]' ,
'[email protected]'
]

Pony.mail (
:to => to_addresses ,
:cc => cc_addresses
)

 

This will certainly be my go-to method from now on. Thanks Jeff!