Skip to content

Instantly share code, notes, and snippets.

@mcsuth
Forked from featherart/gist:7109061
Created October 22, 2013 22:58
Show Gist options
  • Save mcsuth/7109645 to your computer and use it in GitHub Desktop.
Save mcsuth/7109645 to your computer and use it in GitHub Desktop.
rails g UserMailer
class UserMailer < ActionMailer::Base
default from: "fred@fred.com"
def confirm_user(user)
@user = user
@url = 'http://fred.com/login'
mail(to: @user.email, subject: 'Welcome to Fred Site')
end
end
Text version of greeting email (in views/UserMailer/welcome_email.text.erb )
Welcome to example.com, <%= @user.name %>
===============================================
You have successfully signed up to example.com,
your username is: <%= @user.login %>.
To login to the site, just follow this link: <%= @url %>.
Thanks for joining and have a great day!
HTML version (in views/UserMailer/welcome_email.html.erb)
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, <%= @user.name %></h1>
<p>
You have successfully signed up to example.com,
your username is: <%= @user.login %>.<br/>
</p>
<p>
To login to the site, just follow this link: <%= @url %>.
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
Then the configuration files:
for local testing in config/environment/development.rb put something like this:
config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
# location: '/usr/sbin/sendmail',
# arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-replay@example.com'}
You will use the config/environment/production.rb file for deployment to Heroku, and
use the environment variables suggested by SendGrid, or whoever you choose for your
3rd party mailer service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment