Created
February 23, 2009 18:25
-
-
Save mortenbagai/69094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# 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 => "[email protected]", | |
: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 <[email protected]>" | |
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 => '[email protected]', :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