I worked through some basic tutorials on Rails 3. The goal is a community-website on abilities and activities. I am using Devise for authentication. The creation of user profiles with avatars worked well (thanks to paperclip).
As a next step, I want to enable registered users to send an e-mail to a user from his (or her) profile page. I found a great tutorial on creating a contact form using Google Apps:
http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/
The mailer class in this tutorial looks like:
class NotificationsMailer < ActionMailer::Base
default :from => "noreply@youdomain.dev"
default :to => "you@youremail.dev"
def new_message(message)
@message = message
mail(:subject => "[YourWebsite.tld] #{message.subject}")
end
end
My question: What is the best way to replace you@youremail.dev with the receivers E-Mail-Address? (from the User-Model)
Thanks in advance!
You can modify the
new_messageto accept the user (or list of users) to whom you want to send the email. Or an array of email addresses if you want to. Then pass the receiver’s email address to themailmethod as the:tooption.Then you can invoke your mailer like this
To read the API see here or here (I prefer APIdock).
Also a more comprehensive guide on ActionMailer is available here. If you are new to Rails, you can find more guides here.