Skip to content

Commit 7f112bf

Browse files
committed
Configuring the mailer to use Sendgrid and creating a 'welcome' email for new veteran signups.
1 parent 0b70697 commit 7f112bf

10 files changed

Lines changed: 129 additions & 2 deletions

File tree

app/controllers/veterans_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def create
2929

3030
respond_to do |format|
3131
if @veteran.save
32+
UserMailer.welcome(@veteran).deliver
3233
format.html { redirect_to action_path, notice: 'Thanks for signing up!' }
3334
format.json { render :show, status: :created, location: @veteran }
3435
else

app/mailers/user_mailer.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class UserMailer < ActionMailer::Base
2+
default from: "[email protected]"
3+
4+
def welcome(user)
5+
@user = user
6+
mail to: user.email, subject: "Welcome to OperationCode"
7+
end
8+
9+
end

app/models/admin_user.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# == Schema Information
2+
#
3+
# Table name: admin_users
4+
#
5+
# id :integer not null, primary key
6+
# email :string(255) default(""), not null
7+
# encrypted_password :string(255) default(""), not null
8+
# reset_password_token :string(255)
9+
# reset_password_sent_at :datetime
10+
# remember_created_at :datetime
11+
# sign_in_count :integer default(0), not null
12+
# current_sign_in_at :datetime
13+
# last_sign_in_at :datetime
14+
# current_sign_in_ip :string(255)
15+
# last_sign_in_ip :string(255)
16+
# created_at :datetime
17+
# updated_at :datetime
18+
#
19+
120
class AdminUser < ActiveRecord::Base
221
# Include default devise modules. Others available are:
322
# :confirmable, :lockable, :timeoutable and :omniauthable
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<p>
2+
Hooah! Thanks for signing up and joining us in this important fight!
3+
As many of you know I got off active-duty last year and applied to code school, but couldn't use my New GI Bill.
4+
So like any great hacker I'm self-taught. Here's some of the places I've learned at:
5+
</p>
6+
7+
<ul>
8+
<li>
9+
<%= link_to "Programming 'M!' (Good starting point)", "http://programming-motherfucker.com/become.html" %>
10+
</li>
11+
<li>
12+
<%= link_to "CodeAcademy", "http://www.codecademy.com/" %>
13+
</li>
14+
<li>
15+
<%= link_to "Thinkful", "http://www.thinkful.com/" %>
16+
</li>
17+
<li>
18+
<%= link_to "HackHands", "https://hackhands.com/" %>
19+
</li>
20+
</ul>
21+
22+
<p>Good Reading:</p>
23+
24+
<ul>
25+
<li>
26+
<%= link_to "Learn to Program by Chris Pine", "https://pine.fm/LearnToProgram/" %>
27+
</li>
28+
<li>
29+
<%= link_to "Hackers & Painters by Paul Graham", "http://www.paulgraham.com/hp.html" %>
30+
</li>
31+
</ul>
32+
33+
<p>Conferences:</p>
34+
35+
<ul>
36+
<li>
37+
<%= link_to "RailsConf", "http://railsconf.com/" %>
38+
</li>
39+
<li>
40+
<%= link_to "Techstars Patriot Boot Camp", "http://www.techstars.com/patriotbootcamp/" %>
41+
</li>
42+
</ul>
43+
44+
<p>
45+
Lastly, help us get the word out by sharing OperationCode with your battle buddies and friends: http://lnc.hr/PY6P0
46+
</p>
47+
48+
<p>
49+
Thank you, we'll be in touch,<br />
50+
51+
David Molina (<%= link_to "@davidcmolina", "https://twitter.com/davidcmolina"%>)<br />
52+
Founder, OperationCode; <br />
53+
Self-Taught Programmer, and Former U.S. Army Captain
54+
</p>

config/environments/development.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
# JDavis: adding this for Devise.
2020
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
21-
21+
22+
# JDavis: using letter_opener for viewing emails in development
23+
config.action_mailer.delivery_method = :letter_opener
2224

2325
# Print deprecation notices to the Rails logger.
2426
config.active_support.deprecation = :log

config/environments/production.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
config.consider_all_requests_local = false
1515
config.action_controller.perform_caching = true
1616

17+
# JDavis: email settings for Sendgrid
18+
config.action_mailer.delivery_method = :smtp
19+
config.action_mailer.smtp_settings = {
20+
address: 'smtp.sendgrid.net',
21+
port: '587',
22+
user_name: ENV['SENDGRID_USERNAME'],
23+
password: ENV['SENDGRID_PASSWORD'],
24+
domain: 'operationcode.org',
25+
authentication: :plain,
26+
enable_starttls_auto: true
27+
28+
}
1729
config.action_mailer.default_url_options = { host: 'www.operationcode.org' }
1830

1931
# Enable Rack::Cache to put a simple HTTP cache in front of your application

config/initializers/devise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Configure the e-mail address which will be shown in Devise::Mailer,
1111
# note that it will be overwritten if you use your own mailer class
1212
# with default "from" parameter.
13-
config.mailer_sender = '[email protected]'
13+
config.mailer_sender = '[email protected]'
1414

1515
# Configure the class responsible to send e-mails.
1616
# config.mailer = 'Devise::Mailer'

test/fixtures/admin_users.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# == Schema Information
2+
#
3+
# Table name: admin_users
4+
#
5+
# id :integer not null, primary key
6+
# email :string(255) default(""), not null
7+
# encrypted_password :string(255) default(""), not null
8+
# reset_password_token :string(255)
9+
# reset_password_sent_at :datetime
10+
# remember_created_at :datetime
11+
# sign_in_count :integer default(0), not null
12+
# current_sign_in_at :datetime
13+
# last_sign_in_at :datetime
14+
# current_sign_in_ip :string(255)
15+
# last_sign_in_ip :string(255)
16+
# created_at :datetime
17+
# updated_at :datetime
18+
#
19+
120
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
221

322
# This model initially had no columns defined. If you add columns to the
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
2+
class UserMailerPreview < ActionMailer::Preview
3+
4+
end

test/mailers/user_mailer_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class UserMailerTest < ActionMailer::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)