ウェブ 画像 動画 地図 ニュース グループ Gmail その他 »
最近アクセスしたグループ | ヘルプ | ログイン
Google グループ
Errno::EBADF Send an Email in Rails using GMail
現在、このグループで最初に表示するトピックが多すぎます。このトピックを最初に表示するには、別のトピックからこのオプションを削除してください。
リクエストの処理中にエラーが発生しました。 もう一度やり直してください。
フラッグ
  メッセージ 1 件 - すべて折りたたんで表示  -  すべてをに翻訳 翻訳(すべてのオリジナルを表示)
投稿先のグループは Usenet グループです。このグループにメッセージを投稿すると、インターネット上のユーザーがメール アドレスを閲覧できるようになります。
返信メッセージが送信されていません。
投稿しました。
 
差出人:
宛先:
Cc:
フォローアップ先:
Cc を追加 | フォローアップ先を追加 | 件名を編集
件名:
確認:
確認のため、下の画像に表示されている文字か、アクセシビリティ アイコンをクリックすると聞こえる数字を入力してください。 聞こえた番号を入力します
 
Walter Lockhart  
プロフィールを表示   に翻訳 翻訳(オリジナルを表示)
 詳細オプション 2008年7月25日, 午前4:49
差出人: Walter Lockhart <walterlockh...@gmail.com>
日付: Thu, 24 Jul 2008 12:49:58 -0700 (PDT)
ローカル: 2008年7月25日(金) 午前4:49
件名: Errno::EBADF Send an Email in Rails using GMail
Hi,

would someone please help me.  I have been desperatley trying to fnd
out for the last two days why the following code is not working.  Any
ideas.

I'm running Instant Rails 1.4 / Rails version 1.2.5 / Ruby version
1.8.5 (i386-mswin32) / RubyGems version 1.1.1 / Action Mailer version
1.3.5 / Windows XP.

Here is a description of my emailing application:

in app/views/emailer/correspond.rhtml:

<h2>Request A Call Back</h2>

<p>Email a request to receive a Call Back from XYZ:</p>

<% form_tag :action => 'sendmail' do -%>

        <p>First Name:<br /><%= text_field 'email', 'firstname', :size
=> 30 %></p>
        <p>Surname:<br /><%= text_field 'email', 'surname', :size =>
30 %></p>
        <p>Email Address:<br /><%= text_field 'email',
'email_address', :size => 30 %></p>
        <p>Telephone Number:<br /><%= text_field 'email',
'telephone', :size => 30 %></p>
        <p>Message:<br /><%= text_area 'email', 'message_body', :rows
=> 20, :cols => 50 %></p>

    <%= submit_tag "Send", :class => "submit" %> or <%= link_to
'Cancel', '/' %>

<% end -%>

in app/controllers/emailer_controller.rb:

class EmailerController < ApplicationController

   def sendmail
      email = params[:email]
          recipient = '...@def.com'
          subject = 'Request A Call Back'
          firstname = email["firstname"]
          surname = email["surname"]
          email_address = email["email_address"]
          telephone = email["telephone"]
          message_body = email["message_body"]
      Emailer.deliver_message(recipient, subject, firstname, surname,
email_address, telephone, message_body)
      return if request.xhr?
        flash[:notice] = "Email Sent Successfully."
        redirect_to '/emailer/correspond'
   end

end

in app/models/emailer.rb:

class Emailer < ActionMailer::Base

  def message(recipient, subject, firstname, surname, email_address,
telephone, message_body)
    @subject = subject
    @recipients = recipient
    @from = 'no-re...@def.com'

    @body["firstname"] = firstname
    @body["surname"] = surname
    @body["email_address"] = email_address
    @body["telephone"] = telephone
    @body["message_body"] = message_body
  end

end

in app/views/emailer/message.rhtml:

Hi XYZ!

You are receiving an email message from:

First Name:
<%= @firstname %>

Surname:
<%= @surname %>

Email address:
<%= @email_address %>

Telephone Number:
<%= @telephone %>

Message:
<%= @message_body %>

requesting a Call Back.

in config/environment.rb:

   require 'smtp_tls'
   ActionMailer::Base.delivery_method = :smtp
   ActionMailer::Base.server_settings = {
   :address => "smtp.gmail.com",
   :port => 587,
   :domain => "def.com",
   :authentication => :plain,
   :user_name => "a...@googlemail.com",
   :password => "abcdef"
  }

in 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

I get the following error message:

Errno::EBADF in EmailerController#sendmail
Bad file descriptor - connect(2)
RAILS_ROOT: ./script/../config/..

Application Trace | Framework Trace | Full Trace
C:/InstantRails/rails_apps/YOTO/vendor/plugins/action_mailer_tls/lib/
smtp_tls.rb:10:in `initialize'
C:/InstantRails/rails_apps/YOTO/vendor/plugins/action_mailer_tls/lib/
smtp_tls.rb:10:in `open'
C:/InstantRails/rails_apps/YOTO/vendor/plugins/action_mailer_tls/lib/
smtp_tls.rb:10:in `do_start'
C:/InstantRails/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
C:/InstantRails/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
C:/InstantRails/rails_apps/YOTO/vendor/plugins/action_mailer_tls/lib/
smtp_tls.rb:10:in `do_start'
C:/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:378:in `start'
C:/InstantRails/ruby/lib/ruby/1.8/net/smtp.rb:316:in `start'
C:/InstantRails/rails_apps/YOTO/vendor/rails/actionmailer/lib/
action_mailer/base.rb:565:in `perform_delivery_smtp'
C:/InstantRails/rails_apps/YOTO/vendor/rails/actionmailer/lib/
action_mailer/base.rb:451:in `send'
C:/InstantRails/rails_apps/YOTO/vendor/rails/actionmailer/lib/
action_mailer/base.rb:451:in `deliver!'
C:/InstantRails/rails_apps/YOTO/vendor/rails/actionmailer/lib/
action_mailer/base.rb:333:in `method_missing'
C:/InstantRails/rails_apps/YOTO/app/controllers/emailer_controller.rb:
12:in `sendmail'

What on earth is happening?

I have a working version of this code running on Mac OS X with Rails
2.0.2 (with the obvious changes: rhtml --> html.erb and
server_settings --> smtp_settings).

Thanks in advance.

Regards

Walter


    投稿者に返信    転送  
メッセージを投稿するには、ログインする必要があります。
メッセージを投稿するには、まず最初にこのグループに参加する必要があります。
投稿する前に、[設定] ページでニックネームを更新してください。
投稿に必要な権限がありません。
メッセージの終わり
« ディスカッションに戻る « 新しいトピック     過去のトピック »

グループを作成 - Google グループ - Google ホーム - 利用規約 - プライバシー ポリシー
©2009 Google