I'm kind of new at ruby on rails, and I've read many tutorials about this, but I still can't figure out what's wrong.
I already set up the environment.rb with the following lines at the bottom:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 25,
:domain => 'gmail.com',
:authentication => :login,
:user_name => 'myname@gmail.com',
:password => 'mypassword'
}
Then, I've got some code that came with the baseApp I'm using, and it does the开发者_如何转开发 following:
UserMailer.deliver_forgot_password(self)
Where self is the user object, that contains the email, login, etc.
That method(which belongs to the UserMailer class) has the following code:
def forgot_password(user)
setup_email(user)
@subject += "Forgotten password instructions"
#{user.password_reset_code}
@body[:url] = "http://#{Setting.get(:site_url)}/users/reset_password/#"
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = "#{Setting.get(:support_name)} <#{Setting.get(:support_email)}>"
@subject = "[#{Setting.get(:site_name)}] "
@sent_on = Time.now
@body[:user] = user
# Get Settings
[:site_name, :company_name, :support_email, :support_name].each do |id|
@body[id] = Setting.get(id)
end
end
Well, the emails are fine, I've already checked them doing raise inspect, but it's not sending...and it doesn't throw me an exception either.
Now I'm getting Errno::ECONNREFUSED error when trying to send an email. What's wrong now?
Thanks, Brian
Gmail port should be 587 or 465.
and add
:tls => true,
Do you have the ActionMailerTLS Gem installed ?
The new way of doing this as of rails 2.3.2 is
:enable_starttls_auto => true
No need for additional plugins.
On my Mac, I had to turn on postfix to get emails to send. Maybe you don't have a similar mail program turned on capable of sending emails. What that is for Windows 7, I do not know.
精彩评论