Rails Devise Mailer: No Received Messages in Inbox - ruby-on-rails

I'm using Rails 4 and Devise 3. I need to send confirmation e-mails for production. These are the SMTP configs for my config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'smtp.gmail.com' }
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:tls => true,
:port => '587',
:user_name => 'my_email#gmail.com',
:password => 'my_password',
:authentication => 'plain',
:enable_starttls_auto => true
}
Logs say that the e-mail's been sent. However, I don't see anything in the inbox. (yes, mailcatcher is off)
Another question, do the configs of the development file affect the production's environment's in any ways? They shouldn't, correct?
Another important question: Using the way above, how many e-mails can be handled? For an example, if I used a third party say, Mandrill, would be better because up for tens of thousands of e-mails can be handled. What about this way?
P.S I've already tried Mandrill and it worked just fine. I am requested not to use a third party though so I won't be able to use Mandrill.
Lastly, is there any other way of sending the confirmation e-mails from the Rails Devise that I'm unaware of yet? Or are there any other configurations that I need to do OUTSIDE OF RAILS to make this work since I won't be using a third party?

Please make sure you have enter correct host name .
config.action_mailer.default_url_options = { :host => 'your domain name' }
As Rails configuration standard if your application running on local machine it loads development env. file settings, if it is production then it load production env. file settings.
I prefer to use sendgrid or Mandrill by MailChimp, if you ave large application then it is better to use 3rd party addons, for small application you can use Gmail .
hope this will help you :)

Related

Configuring production.rb file to send emails with Rails 4

I am stuck with sending emails in Rails. I need to send password reset or activation account emails using Devise gem. Thanks Devise has email sending functionality builtin. I only need to configure sender. I have googled and found many tutorials on how to do that. Here are the things I still don't understand as many tutorials do not talk about them much:
Any tutorial comes with something like that:
config.action_mailer.default_url_options = { :host => 'gmail.com' }
config.active_support.deprecation = :notify
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# SMTP settings
ActionMailer::Base.smtp_settings = {
:port => 587,
:address => 'smtp.gmail.com',
:domain => 'gmail.com',
:user_name => ENV['username'],
:password => ENV['password'],
:authentication => :plain,
}
So unclear things for me are:
1) what is :host, can I use localhost?, in example it is gmail.com. Do I need to set up some gmail server or whatever.
2) what is :domain, again is it my site domain? or using just gmail.com is fine?
3) What is user_name and password?
So the general question is do I need to install some server for mail on my production server and so on, people on this tutorials skip this part. Who sends my email? Rails app server? or separate smtp server?
1) host is a variable used to generate links to your site in the email (see comment).
2) domain is the sending domain of the email, if you have your own domain you could put your domain there.
3) user name and password are the credentials of your gmail account (or the account that you send mails from). If you have your own smtp relay server set up you can use information for that.
This will likely only work for a minimal number of emails sent, you need to look into a professional service that delivers your emails if you intend on sending more than about 100 per month.

ruby on rails tutorial ch 10 could get mail but links are wrong also Bitbucket could not add the code

I've partially solved this problem: I could get links with confirmation and resetting password.
The problem is that those links pointing to the wrong app and I need to adjust name of app manually in order to get the right redirection. Heroku representative said that those wrong address related to code....
1.Where in the Michael Harti ruby on rails tutorial could I find and change the code?
I've used Cloud 9 and Bitbucket as repository. I've created the new app on Bitbucket clone my existing app from Bitbucket to Cloud and want to push it to Bitbucket in order to make some changes.
But Bitbucket doesn't allow me to do saying that there is the existing app. clone probably doesn't work in this case.
2.How to create exactly the same app as existing in Bitbucket but with different name on Cloud9 and push it to Bitbucket with different name?
thanks.
//config/environments/production.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'tatyanaa.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
If you see that output in console, it means your email was actually sent.
By "sent" I mean that Rails in development mode, instead of really sending the email (so you don't have to setup anything), it outputs it to the console like you can see there.
This configuration can be changed in development.rb by setting
config.action_mailer.delivery_method = :stmp
config.action_mailer.perform_deliveries = true
You are then required to properly configure the smtp settings, check the Action Mailer configuration guide for additional details, should be something like:
config.action_mailer.delivery_method = :stmp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "foo.bar.com",
user_name: "someone",
password: "apassword"
}
However, I highly suggest you to keep the default configuration and let it log in console instead of sending real emails.
Did you properly write the code in production.rb ?
Here is mine (I've followed the same tutorial as well and it worked):
(production.rb)
....
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
host = 'my_heroku_app_name.herokuapp.com'
config.action_mailer.default_url_options = { host: host }
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
....
Also did you properly configure sendgrid as an addon on heroku?
(terminal window)
heroku addons:create sendgrid:starter
If you are stuck and REALLY don't know how to proceed, I recommend you to do the tutorial again from the start. It may seem inefficient to go through the same process again when (I assume) you haven't finished the entire tutorial itself.
Believe me, I've also had the same situation where I "thought" I've followed the every step of the tutorial correctly before the app stopped working for some reason and when I restarted it again from the beginning and followed the steps again, this time with a more relaxed mind, the code worked perfectly :) And I've gone through the same tutorial "4 times" before I could finally "get it". I think it would be good for you if you repeat the same process again as it helps solidify your knowledge AND solve the problem.

Why is my Heroku app not sending emails in production with Sendgrid?

My devise emails work fine in development.
But now that I have pushed to Heroku and am using the sendgrid add-on, they don't get sent. I don't get an error. It seems like it is sent just fine, it is just that it never actually reaches my inbox.
This is my config/environment/production.rb file:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.default_url_options = { :host => 'http://myapp.herokuapp.com' }
config.action_mailer.smtp_settings = {
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:address => 'smtp.sendgrid.net',
:domain => 'myapp.herokuapp.com',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I checked those config vars on Heroku, and they return valid results.
Any ideas?
P.S. I don't have my domain pointing to the Heroku App yet, I just want to test it with the stock Heroku settings first.
Everything look good, did you check if the sendgrid account is provisioned?
If you are on heroku, go to the sendgrid panel to finish the setup, just visit the app profile and under resources(which is the default) you should see the sendgrid add-on, click it and just make sure you have everything setup. In this case it will ask you to setup a template, but you can 'skip' this.
Hope this helps!
This was happening to me too, or something like it. I was using the emails to only send to one email address, for my personal notifications.
It turns out that the email address "bounced" the first time and was being "suppressed" at Sendgrid for future sends. I would check the "suppressions" tab to make sure that's not happening to you.

How do I enable Devise to send out confirmation emails on Heroku?

I am on heroku so am not clear where and how to set it up so that devise can send out emails.
I actually have two directions to go:
I am using sendgrid, so am wondering how it works with that.
For my hand-rolled mailers, I use PostageApp, which I'd prefer because it allows me to see what's going on with my email. The way I use PostageApp is my Mailers are a class of PostageApp's mailer.
Thanks.
In Rails 3 I used the following settings in config/environments/production.rb
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => '##YOUR_PROJECTNAME##.heroku.com' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 25,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN'],
:authentication => :plain
}
Note: you'll need to substitute in your project name - but all those ENV variables are populated for you automatically by heroku.
I just wanted to let you guys know that with the help of one of our customers, we have been able to add integration instructions for Devise with Postage to our documentation. He has also told us that he is updating the code to work with the newer, modularized version of Devise, and he will give us the code as soon as it is ready.

send email from localhost

I'm try learn about email in rails. I'm developing something on localhost. Is it possible to send an email from localhost to say a normal mail account like gmail? Do I have a install a mail server? I've just got a standard rails installation at the moment for development.
Update for rails 4.0
Now you need these code to make it work:
# I recommend using this line to show error
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'mail.google.com',
:port => 587,
:user_name => 'foo#gmail.com',
:password => '******',
:authentication => :plain,
:enable_starttls_auto => true
}
You can set up ActionMailer to use Gmail's SMTP server using something like this in config/environment.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => 'smtp.gmail.com',
:domain => '<your domain>',
:port => 587,
:user_name => '<your gmail>',
:password => '<your password>',
:authentication => :plain
}
Edit: If you experience any difficulties, set your config to display errors:
ActionMailer::Base.raise_delivery_errors = true
Have a look at ActionMailer. In RAILS_ROOT/config/environment/ , there is a file for different environments (development, test, production) the configurable settings go in these files
You specify the delivery_method like this,
ActionMailer::Base.delivery_method = :sendmail
or if you want
ActionMailer::Base.delivery_method = :smtp
A detailed example of the settings has been posted by Mikael S
HTH
If I understand your situation correctly, you want to send an email from your local computer using a custom email address such as john#mycompany.com. If you already registered the domain name for your email account ( mycompany.com ) is very likely that the company that is hosting your website, also has a POP/SMTP server. If so, you can use Mikael S's sample and change the address parameter to your Hosting company's smtp address and use your hosting company's username/password.
If you have not register your custom domain or don't have a hosting provider, you can install a free email server in your local computer. If you use WindowsXP, you can add the IIS email server by going to add/remove programs->windows features. If you are using Linux, you can use any of the email servers available in the repositories. Once you install your local email server you will use Mikael S's sample code and use 127.0.0.1 or localhost in the address field. If you are using WindowsXP's email server, I think you don't have to enter username/password.
Hope it helps you.
You can send it from localhost, you can even set the sender as a 'real' mailbox e.g. you#gmail.com.
However, some (or say most) servers will not accept this mail as part of their spam blocking strategy (inability to verify the sender identity).
However, In the past, I have had something similar with python which worked on gmail.
so good luck ;-)

Resources