Before reading any further please know that everything has been setup as far as implementing the :confirmable
attribute for my user model:
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:facebook]
As well as setting up the code necessary for my development.rb
file:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
To further investigate the issue I decided to use the mailcatcher
gem and the emails are showing that they were sent/recieved:
When I use a real email address this activation message isn't landing in my inbox. At first I thought it may have been because of the known fact that I left the sender's email address to its default that it may have been considered spam. But after changing it to something short and believable, still no luck. Is this because I'm in development
?
Well if you are using Mailcatcher, it is doing exactly what it is supposed to be doing. It is just accepting email delivery on port 1025 and that's that, it won't rely that email anywhere.
MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface.
i.e. You will not deliver these emails to your regular email server like this, you need an SMTP server receiving your connection to deliver this. You could use the following options.
I personally use Sendgrid because it delivers nicely to my inbox without getting flagged as spam etc.
To deliver your email using GMAIL, use the following:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'yourdomain.com',
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
For extra brownie points, do the following to safely store your credentials.
Ok, so what you are looking for to store your credentials, is to use a YAML file with the password/API keys. And never check this file into your repo.
You can reference then this file on your initializers like this, (maybe make the password a global variable or x, use configatron, etc, up to you).
But this is basically how production applications work, they read their important settings from a YAML file stored on the server itself.
This is what I use:
# Per environment settings
app_settings = YAML.load_file('config/secret_stuff.yml')
password = app_settings['mygmailpwd']
Do not use ENVIRONMENT variables because they have all sort of security issues. They are an antipattern.