开发者

Ruby on Rails 3: help with sending emails

I have the following setup to send email at sign up:

Rails 3.0.7

ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

rails plugin install git://github.com/collectiveidea/action_mailer_optional_tls.git

Mailer

开发者_如何学运维class UserMailer < ActionMailer::Base

    def registration_confirmation(user)
    recipients  user.email
    from        "webmaster@example.com"
    subject     "Thank you for Registering"
    body        :user => user
    end
end

Controller:

   def create
    @user = User.new(params[:user])
    if @user.save
       UserMailer.deliver_registration_confirmation(@user)
       sign_in @user
       flash[:success] = "Welcome to ECE"
       redirect_to @user
    else
      @title = "Sign up"
      render 'new'
    end
   end

View:

Hi <%= @user.name %>, .....

I was getting smtp connection errors and I included this in gemfile after googling.

This is solved the error

Gemfile

 gem 'rack-ssl', :require => 'rack/ssl'

Config/environment/development.rb

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.middleware.insert_before ActionDispatch::Static, "Rack::SSL"
  config.action_mailer.smtp_settings = {
     :enable_starttls_auto => true,
     :address        => 'smtp.gmail.com',
     :authentication => :login,
     :port           => 587,
     :domain         => 'www.example.com',
     :name           => 'user@gmail.com',
     :password       => 'password',
   }

Problem

earler I was getting 535-5.7.1 Username and Password not accepted.

Now it says:

SSL connection error

Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.

Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.

Any suggestion?


I've been using gmail for sending emails, and have never configured any extra gems. This is what I've in development.rb.

config.action_mailer.smtp_settings = {
    :tls => true,
    :enable_starttls_auto => true,
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "domain.com",
    :authentication => :plain,
    :user_name => "user@domain.com",
    :password => "password"
}

The points to be noted are:

Note: The value for :domain is google apps domain. I think its not required if you are using the username which belongs to gmail.com.


The rails guide has a gmail example. They have authentication set to plain. Maybe give it a shot?

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'baci.lindsaar.net',
  :user_name            => '<username>',
  :password             => '<password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

http://edgeguides.rubyonrails.org/action_mailer_basics.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜