yerassyl
yerassyl

Reputation: 3048

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?

Upvotes: 1

Views: 905

Answers (1)

xyious
xyious

Reputation: 1073

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.

Upvotes: 2

Related Questions