# Recommending friends, using RoR's Mailer

**URL:** <https://www.ruby-forum.com/t/recommending-friends-using-rors-mailer/183149>\
**Category:** Rails\
**Created:** [February 9, 2010, 12:28am UTC](https://www.ruby-forum.com/t/recommending-friends-using-rors-mailer/183149 "2010-02-09T00:28:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 9, 2010, 12:28am UTC](https://www.ruby-forum.com/t/recommending-friends-using-rors-mailer/183149/1 "2010-02-09T00:28:19Z")

</div>

Hi there, I wan tto be able to allow users to invite friends…

The action below is exactly the same as the code used to send a user  
their username. Only difference is, I need to change the ‘‘user =  
User.find\_by\_email(email)’’ part as obviously, I dont want to only  
email people who are already on the site.

def invite  
@title = “Invitation”

```
    if param_posted?(:user)
      email = params[:user][:email]
      user = User.find_by_email(email)
      if user
      UserMailer.deliver_invite(@user)
      flash[:notice] = "Invite sent."
      redirect_to :action => "index", :controller => "site"
      else
      flash[:notice] = "There is no user with that email

```

address."  
end  
end  
end

The UserMailer code is below:  
def invite(user)  
@subject = ‘Invitation’  
@body = {}  
# Give body access to the user information.  
@body[“user”] = user  
@recipients = user.email  
@from = ‘[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)’

end

The last part is the call to the UserMailer that picks the template to  
send the relevant email…

UserMailer.deliver\_invite(@user)

the \_invite is the template in which is ultimately displayed to the  
chosen invitee.

ANy ideas how this can be altered to allow for the mail to be sent to  
anyone added to the input field?

Many Thanks
