Reputation: 209
I didn't figure out how I send mail from gmail in development environment.It didn't send email. I didn't understand the rails guide, and also I wonder if the production env is the same ?
config/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'something.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'mail.google.com',
user_name: '[email protected]',
password: 'mypassword',
authentication: 'plain',
enable_starttls_auto: true }
mailer/user_mailer.rb
default :from => 'something.com'
def welcome_email(user)
@user = user
@url = 'http://something.com'
mail(to: @user.email, subject: 'Welcome')
end
where I call, in users create method,
UserMailer.welcome_email(@user).deliver_now
Upvotes: 2
Views: 610
Reputation: 4156
You can call your mailer methods in two way to send email,
In UsersController
's create
action
def create
#your codes and logics to save user...
UserMailer.welcome_email(@user).deliver_now
#your codes goes here ...
end
In User
model after_create
callback
class User < ActiveRecord::Base
after_create :send_email
def send_email
UserMailer.welcome_email(self).deliver_now
end
end
I would prefer second one for sending email, use model callback rather in controller.
Upvotes: 0
Reputation: 854
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
Try this in development.rb
It will either send mail or raise delivery error in console.
Upvotes: 2