Redmine:通过gmail错误SSL_connect或STARTTLS发送邮件

mpg*_*pgn 1 ruby email gmail ruby-on-rails redmine

我尝试为电子邮件通知配置redmine

所以我的配置configuration.yml是:

production:
   email_delivery:
     delivery_method: :smtp
     smtp_settings:
       enable_starttls_auto: true
       address: "smtp.gmail.com"
       port: '587'
       domain: "smtp.gmail.com"
       authentication: :plain
       user_name: "mymail@gmail.com"
       password: "mypass"
Run Code Online (Sandbox Code Playgroud)

根据本教程:

http://www.redmine.org/projects/redmine/wiki/EmailConfiguration#Simple-Login-Authentication-default-settings

但是当我尝试:发送测试邮件时,我有这个错误:

An error occurred while sending mail (530 5.7.0 Must issue a STARTTLS command first. n7sm25368265eef.5 - gsmtp )
Run Code Online (Sandbox Code Playgroud)

如果我有 :

production:
   email_delivery:
     delivery_method: :smtp
     smtp_settings:
       tls: true
       enable_starttls_auto: true
       address: "smtp.gmail.com"
       port: '587'
       domain: "smtp.gmail.com"
       authentication: :plain
       user_name: "mymail@gmail.com"
       password: "mypass"
Run Code Online (Sandbox Code Playgroud)

我有这个错误:

An error occurred while sending mail (SSL_connect returned=1 errno=0 state=unknown state: unknown protocol)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗 ?Redmine版本:2.0.1,Ruby:1.9.3

Pee*_*ush 5

1.在rails应用程序中保存以下代码lib/smtp_tls.rb:

require "openssl"
require "net/smtp"

Net::SMTP.class_eval do
  private

  def do_start(helodomain, user, secret, authtype)
    raise IOError, 'SMTP session already started' if @started
    check_auth_args user, secret, authtype if user or secret

    sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
    @socket = Net::InternetMessageIO.new(sock)
    @socket.read_timeout = 60 #@read_timeout
    #@socket.debug_output = STDERR #@debug_output

    check_response(critical { recv_response() })
    do_helo(helodomain)

    if starttls
      raise 'openssl library not installed' unless defined?(OpenSSL)
      ssl = OpenSSL::SSL::SSLSocket.new(sock)
      ssl.sync_close = true
      ssl.connect
      @socket = Net::InternetMessageIO.new(ssl)
      @socket.read_timeout = 60 #@read_timeout
      #@socket.debug_output = STDERR #@debug_output
      do_helo(helodomain)
    end

    authenticate user, secret, authtype if user
    @started = true
  ensure
    unless @started
      # authentication failed, cancel connection.
      @socket.close if not @started and @socket and not @socket.closed?
      @socket = nil
    end
  end

  def do_helo(helodomain)
    begin
      if @esmtp
        ehlo helodomain
      else
        helo helodomain
      end
    rescue Net::ProtocolError
      if @esmtp
        @esmtp = false
        @error_occured = false
        retry
      end
      raise
    end
  end

  def starttls
    getok('STARTTLS') rescue return false
    return true
  end

  def quit
    begin
      getok('QUIT')
    rescue EOFError, OpenSSL::SSL::SSLError
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

2.将此代码添加到config/environment.rb(在其他所有内容之后):

require “smtp_tls”

ActionMailer::Base.smtp_settings = {
  :address => “smtp.gmail.com”,
  :port => 587,
  :authentication => :plain,
  :user_name => “someone@openrain.com”,
  :password => ’someonesPassword’
} 
Run Code Online (Sandbox Code Playgroud)

3.正常使用ActionMailer.