Skip to content

Instantly share code, notes, and snippets.

@KillerDesigner
Forked from featherart/gist:7109061
Created October 22, 2013 22:53
Show Gist options
  • Select an option

  • Save KillerDesigner/7109581 to your computer and use it in GitHub Desktop.

Select an option

Save KillerDesigner/7109581 to your computer and use it in GitHub Desktop.

Revisions

  1. Feather created this gist Oct 22, 2013.
    57 changes: 57 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    rails g UserMailer

    class UserMailer < ActionMailer::Base
    default from: "[email protected]"

    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: '[email protected]'}

    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.