取得"を発しなければならないSTARTTLSコマンド初の"しようとした場合にメール送信

StackOverflow https://stackoverflow.com/questions/1641354

  •  08-07-2019
  •  | 
  •  

質問

もしかしたらエラーが対応しようとしているそうだ、 action_mailer_tls プラグインと通信のGmailメールマレールアプリ

Must issue a STARTTLS command first

その他いた このと同じ問題:

問題は、Gmail)での設定が必要でTLS 認証基準はいずれもRuby 純/smtp図書館に対応しておりませんTLSを表示します。

記事を推奨以下の操作を行うことで、私た:

のコースがありプラグイン 作成したマChungこ バリアになります。きこと 手動で追加するプロジェクトまたはお エクスポートすることができますプラグイン ディレクトリです。

  1. $ cd vendor/plugins
  2. $ svn export http://code.openrain.com/rails/action_mailer_tls/

どちら確認が必要とな 'smtp_tls'

今必要なのはアップデート smtp_settingsださい ています。

  1. ActionMailer::ベース。smtp_settings={
  2. アドレス=>"smtp.gmail.com",
  3. :port=>587,
  4. :ドメイン"domain.com",
  5. :user_name=>"user@domain.com",
  6. パスワード=>パスワード
  7. :認証=>:平野
  8. }

あらゆる提案のためのより良い解決へのGmailメールによりお願い申し上げます。

役に立ちましたか?

解決

Alexander Pomozovのソリューションを使用して、RailsアプリからGmailと通信しました。元の記事はなくなったと思うが、誰かがGoogleキャッシュこちら

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

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’
    } 

ActionMailerを通常どおり使用します。

他のヒント

Ruby 1.8.7およびRails 2.3.4(いくつかのリリースにありますが)では、:enable_starttls_auto オプションを使用することで、TLS固有のActionMailerプラグインを必要とせずに成功しました。 (実稼働環境からの)サンプル構成は次のようになります。

ActionMailer::Base.smtp_settings = {
  :enable_starttls_auto => true,
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "domain.com",
  :authentication => :plain,
  :user_name => "username@domain",
  :password => "secret"
}

あったか有効にstarttlsを使用 :enable_starttls_auto => true ずっと同じエラーになります。ついにでましたのでそれを解決することなく、単一のコードです。ご利用の場合smtp.gmail.com メールの送信時に、初めの安全アプリをご利用のメールを送ります。そのログイン後、お客様の口座から送信したいメールへ このリンクon アクセスを確保。
編集:場合ことができませんので、設定を変更するための安全アプリがあり、その管理用アカウントを以下のコマンホルダーのドメインの設定を変更するためのユーザーの安全アプリとなります。
を持っていれば管理者権利を許可するにはユーザーに変更する安全アプリ設定変更ができますか https://admin.google.com/domainname.com/AdminHome#ServiceSettings/notab=1&service=securitysetting&subtab=lesssecureappsaccess
PS:お忘れなく変更するドメイン種別に上記のリンクです。

こheps!!

rails 2.3.4を実行していますが、(グーグルから)あなたはプラグインを必要とせず、行のみを必要とすると考えましたが

:enable_starttls_auto => true、

実際には、上記のスキーが投稿したAlexander Pomozovのソリューションを使用して初めて機能しました(皆さんに感謝します)。理由について何かコメントはありますか?素晴らしいと思いますが、うまくいくだけで嬉しいです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top