Reputation: 319
I can't sen email from localhost. Here is my code. At first I was generate mailer UserMailer. enviroment.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:adress => '[email protected]',
:port => 25,
:authentication => :login,
:user_name => 'johnoggy3010',
:password => 'secret'
}
mailers/user_mailer:
class UserMailer < ActionMailer::Base
def mail(user)
rexipients '[email protected]'
from '[email protected]'
subject = "Hi"
body :user => user
end
end
my controller:
UserMailer.deliver_mail(params[:name])
and template in user_mailer/welcome_email.html.erb:
<h1>Welcome to example.com,<%= user %> </h1>
But somthing is wrong and I don't know what exacally...
Upvotes: 0
Views: 87
Reputation: 81
make your setting correct.Here is the code for using gmail smtp :
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'your host' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => '587',
:authentication => :plain,
:user_name => 'your full email addess like [email protected]',
:password => 'your account password',
:domain => 'your domain'
}
In your development.rb write this following line to see if there is any error happening:
config.action_mailer.raise_delivery_errors = true
In your mailer first try to send this simple email:
def deliver_oggymail()
mail(:to => "[email protected]", :subject => ="hi")
end
In your controller
UserMailer.deliver_oggymail().deliver
Upvotes: 1