Rails 3: SMTP Settings for Google Apps / Heroku - ruby-on-rails

Here are my smtp settings for Google Apps in setup_mail.rb.
:address => "smtp.gmail.com",
:port => 587,
:domain => 'mysite.co',
:user_name => 'noreply#mysite.co',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true
My development logs show in detail the e-mails being generated and sent to the right e-mail address... but they are not arriving. I can only think that there must be something wrong with the settings above. Can you see what the problem is?
Once this is solved, would I have any issue getting it to work on Heroku?
Note: the above is logging a deprecation warning:
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance va
riables instead. (called from process at C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gem
s/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77)

I think if you are using rails 3, the correct approach to setup mail would be to follow this railscasts tutorial on action mailer.

in your user controller don't forget to add the .deliver
UserMailer.registration_confirmation(#user).deliver
that is what stumped me

Turned out that the issue was elsewhere - an old AuthLogic tutorial had put me in the right direction on sending out activation codes but the wrong direction on sending out the e-mails themselves. Rails was generating the e-mail but not sending it because the mail_helper's code wasn't going the final step.
If you're reading this in retrospect, what I learned: make sure your Rails 3.0 user_mailer has (or similar):
mail(:to => "#{user.login} <#{user.email}>", :subject => "Registered" )

I haven't used rails3 but I remember reading that sent emails in development are sent to the sender. Your deprecation warning is because you're defining variables for the email template in the previous hash format. Rails 3 works differently. In my experience deploying to heroku works flawlessly but you will need to define mx records.

Related

Rails Devise Mailer: No Received Messages in Inbox

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 :)

Using Sidekiq with Mailer to send asynchronous emails [RAILS]

So I am currently trying to use the Rails gem 'sidekiq' to send a large number of emails asynchronously, so it does not bog down the load time for the next page.
Everything I have works except for this:
FeedbackMailer.invite_contact(current_user, current_business, contact).deliver()
This is my own mailer and a set of paramters which it must take to create the email for the client.
The error that gets thrown by sidekiq is this:
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
The default_url_options[:host] is set in the application.rb, but does not seem to get read here. I also tried setting only_path: true and got the same error still.
I can send emails just find when I am outside one of sidekiq's workers, the problem only exists there. Anyone know of a workaround so that emails can be sent from sidekiq's workers?
Also before you answer, using Mailer.delay doesnt really solve my problem, because there is alot of other code around the mailing that must go off during every iteration of the loop.
This error happens when your mail is not configured properly. Check that you have something like this in the relevant environment file (production.rb or staging.rb)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.something.com',
:port => 587,
:domain => 'yourdomain.com',
:user_name => 'account-admin#yourdomain.com',
:password => 'your secure password',
:authentication => 'plain',
:enable_starttls_auto => true
}

Rails Mailer is not actually sending emails

I have just started learning ruby on rails and this was one of the tutorials i followed:
http://railscasts.com/episodes/206-action-mailer-in-rails-3
I followed it to a T and I have yet to receive anything in my gmail account. Is it fair to assume some updates to ruby have changed how you do things?
My best guess from reading everything over the net, the tutorial is missing actually setting the mailer to use smtp setting.
Here are my smtp settings:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "alexei.herokuapp.com",
:user_name => "mygmailaccount",
:password => "mygmailpassword",
:authentication => "plain"
:enable_starttls_auto => true
}
Could it be that i am still in local environment when testing this?
In that Railscast, Ryan has a line in there that doesn't send any email in development:
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
Did you put that in? If so, then no email will go out when you run your app locally in development.
Try removing it.
Also open myapp/logs/development.log to see if what shows up there when you try to send an email.

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.

Rails 3 - sendgrid setup to support devise

I'm trying to get sendgrid running on my Rails 3 App with Devise, so devise can send out registration emails etc..
I added the following, config/setup_mail.rb:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => '25',
:domain => "XXXXXXXXX.com",
:authentication => :plain,
:user_name => "XXXXXXXXXXX#gmail.com",
:password => "XXXXXXXXXX"
}
Shouldn't that be enough for Rails + Devise to send out registration emails? Or do I need something else or a gem of some kind?
The logs show the email being generated but I don't see anything in the log about MAIL being sent successfully or erroring. And my sendgrid account still says 0/200 emails sent.
Is there a better way in Rails to see what's going on when it trys to send the email?
Thanks
You can erase the setup that you have.
heroku addons:create sendgrid:free
That is the only pieces of code you need to get email configured with heroku.
Make sure you have your host link setup which I think you did because it will cause it to crash but if you haven't:
config.action_mailer.default_url_options = { :host => 'myapp.heroku.com' }
Actually this last lien is different on rails3 so watch out for that :)
The "config" line needs to be added to your "production.rb" file.
I'm searching for the same answer myself. In intializers/devise.rb I read:
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
I wonder if Devise has to be told to use Actionmailer.

Resources