Basic email

Hi There,

Anyone know of a nice basic way to send an email in ruby on rails?

I’m thinking of allowing my site members to reccomend/invite friends
by entering their email address and hitting send.

At a guess, to begin with I think i’d need:

def message(mail)
subject mail[:message].subject
from ‘someone’
recipients mail[:recipient].email
body mail
end

then a message page, which is displayed to the user in the email
invitation they receive: similar to:

<%= @user.name %> at site ABC123 thinks you should check out this
site:

site name and url here…

Is there a way to implement this in a nice easy way, ensuring that a
user can log in, enter a friend’s email address, send it and their
friend recieve the invite?

cheers

A framework for sending emails is already built into Rails. Its called
ActionMailer.
http://wiki.rubyonrails.org/howtos/mailers

I recommend Action Mailer Basics — Ruby on Rails Guides it
is a good place to get started.

If you had a mailer named CraigMailer and you had the message defined
like above

class CraigMailer < ActionMailer::Base

def message(mail)
subject mail[:message].subject
from ‘someone’
recipients mail[:recipient].email
body mail
end

end

Then you can send your email by calling
CraigMailer.deliver_message(mail) which will send your email provided
you have smtp settings setup in your production.rb file.


Richard S.
http://whyspam.me