Skip to content

Instantly share code, notes, and snippets.

@mortenbagai
Created February 23, 2009 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenbagai/69094 to your computer and use it in GitHub Desktop.
Save mortenbagai/69094 to your computer and use it in GitHub Desktop.
###
# Configuration
###
# Make sure the delivery method is SMTP. Sendmail won’t work, Pony either since it relies on it.
config.action_mailer.delivery_method = :smtp
# Set up your SMTP server connection:
ActionMailer::Base.smtp_settings = {
:address => "smtp.someserver.net",
:port => 25,
:user_name => "someone@someserver.net",
:password => "mypass",
:authentication => :login
}
# You might want to make sure Rails raises exceptions on mail delivery. By default this is turned off for the development environment, so you can turn it on with
config.action_mailer.raise_delivery_errors = true
###
# Usage
###
# Use script/generate mailer <name> to generate a class. It could look something like:
class UserMailer < ActionMailer::Base
def signup_notification(user)
recipients "#{user.name} <#{user.email}>"
from "My Forum <forum@mysite.com>"
subject "Please activate your new account"
sent_on Time.now
body { :user => user, :url => activate_url(user.activation_code, :host => user.site.host }
end
end
# and the corresponding view:
And the view in app/views/user_mailer/signup_notification.rhtml looks like this:
Your account has been created.
Username: <%= @user.login %>
Password: <%= @user.password %>
# Test from the console like this:
user = User.new(:name => 'Me', :email => 'me@gmail.com', :login => 'me', :password => '1234') # or find a record...
UserMailer.deliver_signup_notification(user)
# or write it directly into your model:
after_create :deliver_signup_notification
def deliver_signup_notification
UserMailer.deliver_signup_notification(self)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment