Skip to content

Commit

Permalink
Intercept email in development by default
Browse files Browse the repository at this point in the history
- Actually "sends" out email without need to configure an SMTP host locally
- Lets you use all kinds of email addresses, not just real ones
- Prevents you from spamming yourself and others while developing
  • Loading branch information
TildeWill committed Aug 9, 2015
1 parent 9e8f9bf commit 71b2bfd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ INVITATION_CODE=try-huginn
# Outgoing email settings. To use Gmail or Google Apps, put your Google Apps domain or gmail.com
# as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
#
# PLEASE NOTE: In order to enable emails locally (e.g., when not in the production Rails environment),
# PLEASE NOTE: In order to enable sending real emails via SMTP locally (e.g., when not in the production Rails environment),
# you must also set SEND_EMAIL_IN_DEVELOPMENT to true below.
#
# If you have trouble with port 587 on Gmail, you can also try setting
Expand All @@ -68,7 +68,8 @@ SMTP_PORT=587
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=true

# Send emails when running in the development Rails environment.
# Set to true to send real emails via SMTP when running in the development Rails environment.
# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
SEND_EMAIL_IN_DEVELOPMENT=false

# The address from which system emails will appear to be sent.
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ group :development do
gem 'guard'
gem 'guard-livereload'
gem 'guard-rspec'
gem 'letter_opener_web'

group :test do
gem 'coveralls', require: false
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ GEM
kramdown (1.3.3)
launchy (2.4.2)
addressable (~> 2.3)
letter_opener (1.4.1)
launchy (~> 2.2)
letter_opener_web (1.3.0)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
libv8 (3.16.14.7)
liquid (3.0.6)
listen (2.7.9)
Expand Down Expand Up @@ -529,6 +535,7 @@ DEPENDENCIES
jsonpath (~> 0.5.6)
kaminari (~> 0.16.1)
kramdown (~> 1.3.3)
letter_opener_web
liquid (~> 3.0.3)
mini_magick
mqtt
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ If you just want to play around, you can simply fork this repository, then perfo
* Read the [wiki][wiki] for usage examples and to get started making new Agents.
* Periodically run `git fetch upstream` and then `git checkout master && git merge upstream/master` to merge in the newest version of Huginn.

Note: by default, emails are not sent in the `development` Rails environment, which is what you just setup. If you'd like to enable emails when playing with Huginn locally, set `SEND_EMAIL_IN_DEVELOPMENT` to `true` in your `.env` file.
Note: By default, emails are intercepted in the `development` Rails environment, which is what you just setup. You can view
them at [http://localhost:3000/letter_opener](http://localhost:3000/letter_opener). If you'd like to send real emails via SMTP when playing
with Huginn locally, set `SEND_EMAIL_IN_DEVELOPMENT` to `true` in your `.env` file.

If you need more detailed instructions, see the [Novice setup guide][novice-setup-guide].

Expand Down
7 changes: 5 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@

config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
config.action_mailer.asset_host = ENV['DOMAIN']
config.action_mailer.perform_deliveries = ENV['SEND_EMAIL_IN_DEVELOPMENT'] == 'true'
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
if ENV['SEND_EMAIL_IN_DEVELOPMENT'] == 'true'
config.action_mailer.delivery_method = :smtp
else
config.action_mailer.delivery_method = :letter_opener
end
# smtp_settings moved to config/initializers/action_mailer.rb
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
devise_for :users,
controllers: { omniauth_callbacks: 'omniauth_callbacks' },
sign_out_via: [:post, :delete]

if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener"
end

get "/about" => "home#about"
root :to => "home#index"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ INVITATION_CODE=try-huginn
# Outgoing email settings. To use Gmail or Google Apps, put your Google Apps domain or gmail.com
# as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
#
# PLEASE NOTE: In order to enable emails locally (e.g., when not in the production Rails environment),
# PLEASE NOTE: In order to enable sending real emails via SMTP locally (e.g., when not in the production Rails environment),
# you must also set SEND_EMAIL_IN_DEVELOPMENT to true below.

SMTP_DOMAIN=your-domain-here.com
Expand All @@ -57,7 +57,8 @@ SMTP_PORT=587
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=true

# Send emails when running in the development Rails environment.
# Set to true to send real emails via SMTP when running in the development Rails environment.
# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
SEND_EMAIL_IN_DEVELOPMENT=false

# The address from which system emails will appear to be sent.
Expand Down

0 comments on commit 71b2bfd

Please sign in to comment.