# Creating an email array based off search results

**URL:** <https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442>\
**Category:** Rails\
**Created:** [April 10, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442 "2008-04-10T21:25:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Etandrib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@Etandrib](https://www.ruby-forum.com/u/Etandrib)\
**Post date:** [April 10, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442/1 "2008-04-10T21:25:34Z")

</div>

I’m trying to perform a search a a list of people and then create an  
email based on the emails found in the result set. Any idea how to do  
this? I figure this is a model topic as I need the figure out the  
logic to generate an array of the emails in the results set. I’m using  
the acts\_as\_ferret plugin and the instance variable is @volunteers  
which means that the emails I need are in the instance variable  
@volunteers but I don’t know how to get them out of it and into the  
mail\_to link below - hopefully in the form of a nice method like  
“volunter\_emails\_from\_search” below.

The code to generate the email looks like the following:

```auto
<%= mail_to "#{volunter_emails_from_search}", "Email", :subject =>
"This is an example email" %>
```

---

<div class="post-metadata">

**Author:** ![Etandrib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@Etandrib](https://www.ruby-forum.com/u/Etandrib)\
**Post date:** [April 11, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442/2 "2008-04-11T16:51:38Z")

</div>

Is @volunteers an array of Volunteer models, perhaps where each has  
an :email attribute?

Assuming that, it’s just a matter of iterating…

\<% @volunteers.each do |volunteer| %\>  
\<%= mail\_to volunteer.email, volunteer.email, :subject =\> “the  
example subject” %\>  
\<% end %\>

The “volunteer.email” is listed twice because it’s the link and it’s  
the display for the link.

Does that help? Or were you needing something else?

-Danimal

---

<div class="post-metadata">

**Author:** ![Etandrib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@Etandrib](https://www.ruby-forum.com/u/Etandrib)\
**Post date:** [April 14, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442/3 "2008-04-14T16:27:20Z")

</div>

I’m actually looking to have one mail link that will mail to all the  
recipients below. So if I have 5 volunteers in the search results I  
can email them with a single click. Iterating just gives me multiple  
email links which I can easily do with the results. This should be a  
really easy thing to do I just can’t figure out how to pass an array  
of email address to the mail\_to parameters so I have a single link  
with an array of addresses.

---

<div class="post-metadata">

**Author:** ![Etandrib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@Etandrib](https://www.ruby-forum.com/u/Etandrib)\
**Post date:** [April 14, 2008, 11:49pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442/4 "2008-04-14T23:49:38Z")

</div>

> **[SightSpecific.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=sightspecific.com)**
>
> Get the premium .com domain you deserve. Seamless and professional transactions. Payment plans available.

The problem is that there is no ideal way to include multiple  
addresses in the mail\_to link.

So, I see two options:

1. just use one of the “nonstandard” ways, like having a list of email  
addresses separated by commas, or
2. instead of using a mail\_to link, have it call an action and have  
that action use ActionMailer. Then, you can specify all the addresses  
you need.

If you go with option 1, just use: join(“,”) on the email addresses  
array.

If you go with option 2, which is much better but more work, you can  
pass the array in as the recipients list.

HTH!

-Danimal

---

<div class="post-metadata">

**Author:** ![Etandrib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bbce88/32.png) [@Etandrib](https://www.ruby-forum.com/u/Etandrib)\
**Post date:** [April 14, 2008, 5:54pm UTC](https://www.ruby-forum.com/t/creating-an-email-array-based-off-search-results/134442/5 "2008-04-14T17:54:38Z")

</div>

Etandrib wrote:

> I’m actually looking to have one mail link that will mail to all the  
> recipients below. So if I have 5 volunteers in the search results I  
> can email them with a single click. Iterating just gives me multiple  
> email links which I can easily do with the results. This should be a  
> really easy thing to do I just can’t figure out how to pass an array  
> of email address to the mail\_to parameters so I have a single link  
> with an array of addresses.

Create a button in the view that will post back with the list of  
addressees, and have the controller call a model method to do the  
emails… somebody somewhere will have to do the iteration, and I’d  
guess it should be the controller, unless you have a volunteer\_list  
model that understands multiple volunteers.
