I am creating a simple non-profit application with Ruby on Rails. I have to set up the following settings in order to be able to send emails with Gmail:
Depot::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address:"smtp.gmail.com",
port:587,
domain:"domain.of.sender.net",
authentication: "plain",
user_name:"dave",
password:"secret",
enable_starttls_auto: true
}
end
I am completely new with this stuff and have no idea what exactly I should do.
Also, as it is said here:
Setting up an email server is a difficult process involving a number of different programs, each of which needs to be properly configured.
because of this and my poor skills I am looking for the simplest solution.
I have read the rails action mailer tutorial and have an idea about what these parameters are used for, but the things around the Gmail and the mail server are not clear at all.
The configuration of your mailer should/can be defined in both development
and production
the purpose of this configuration is that when you set this up when you use the actionmailer
these SMTP options will be used. You could have a simple mailer like the following:
Mailer
class UserMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def registration_confirmation(user)
@user = user
@url = "http://portal.herokuapp.com/login"
mail(:to => user.email, :subject => "Registered")
end
end
Controller
def create
@title = 'Create a user'
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
redirect_to usermanagement_path
flash[:success] = 'Created successfully.'
else
@title = 'Create a user'
render 'new'
end
end
So what happens here is that when the create
action is being used this fires the mailer UserMailer
Looking at the above UserMailer it uses the ActionMailer as the base. Following the SMTP setup shown below which can be defined in both config/environments/production.rb
and development.rb
You would have the following:
config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => '[email protected]',
:password => 'pass',
:authentication => 'login',
:enable_starttls_auto => true
}
If you want to define the SMTP settings in development mode you would replace
config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
with
config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' }
This should be a thorough enough explanation to kick start you in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With