Mailing error in Rails 2.3.2

Hi,

My mails were working with the earlier version of rails ie. Rails
2.0.2. But recently when i upgraded my environment to 2.3.2 the mails
stopped working and gave
“Error: End of file reached”.
But if i send mails independent of my rails app the mailing code works
fine.

My Environment:
Windows Xp
Ruby 1.8.7
actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
archive-tar-minitar (0.5.2)
cgi_multipart_eof_fix (2.5.0)
color (1.4.0)
dbd-odbc (0.2.4)
dbi (0.4.0)
deprecated (2.0.0)
gem_plugin (0.2.3)
hoe (1.8.2)
mongrel (1.1.5)
pdf-writer (1.1.8)
rails (2.3.2)
rake (0.8.4)
rubyforge (1.0.2)
transaction-simple (1.4.0)

Here is my test mails code:

sample_mail.rb →

class SampleMail
require ‘send_email’
def sample_mail()
to_addr = ‘[email protected]
subject = ‘Mail Testing’
body = ‘This is a mail to test the mails.’
hsh={:to=> to_addr, :subject=> subject, :body=> body}
SendEMail.send_email(hsh)
end
end

s = SampleMail.new
s.sample_mail()


send_email.rb →

#!/usr/bin/env ruby
require ‘rubygems’
gem ‘actionmailer’
require ‘action_mailer’
require ‘openssl’
require ‘net/smtp’

module SendEMail

@user_name= ‘[email protected]
@domain=‘@somedomain.com
@password=‘password’

def SendEMail.send_email(hsh)

raw_attachments = []
if hsh.has_key?(:raw_attachment)
raw_attachments.push(hsh[:raw_attachment])
end

mail=TMail::Mail.new
mail.to=hsh[:to]
mail.date=Time.now
mail.from=@user_name
mail.subject=hsh[:subject]

main=mail
main=TMail::Mail.new
main.body = hsh[:body]
puts main.body
main.set_content_type(‘text/plain’, nil, ‘charset’=>‘utf-8’)
mail.parts.push(main)

for raw_attachment in raw_attachments
part = TMail::Mail.new
transfer_encoding=raw_attachment[:transfer_encoding]
body=raw_attachment[:body]
case (transfer_encoding || “”).downcase
when “base64” then
part.body = TMail::Base64.folding_encode(body)
when “quoted-printable”
part.body = [body].pack(“M*”)
else
part.body = body
end

part.transfer_encoding = transfer_encoding
part.set_content_type(raw_attachment[:mime_type], nil, ‘name’ =>
raw_attachment[:filename])
part.set_content_disposition(“attachment”, “filename”=>raw_attachment
[:filename])
mail.parts.push(part)
end

mail.set_content_type(‘multipart’, ‘mixed’)
ActionMailer::Base.deliver(mail)

end

ActionMailer::Base.smtp_settings = {
:address => ‘smtp.gmail.com’,
:domain => @domain,
:authentication => :plain,
:port => 587,
:user_name => @user_name,
:password => @password
}

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
check_auth_args user, 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)

raise ‘openssl library not installed’ unless defined?(OpenSSL)
starttls
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)

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’)
end

def quit
begin
getok(‘QUIT’)
rescue EOFError, OpenSSL::SSL::SSLError
end
end
end
end


This code works if not included with my rails app and run through
command prompt.
If this code is integrated in rails app it gives me "Error: End of
file reached "

If anyone has any idea please help…

Here is the stack trace

c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:135:in sysread' c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:135:inrbuf_fill’
c:/ruby-1.8.7/lib/ruby/1.8/timeout.rb:62:in timeout' c:/ruby-1.8.7/lib/ruby/1.8/timeout.rb:93:intimeout’
c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:134:in rbuf_fill' c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:116:inreaduntil’
c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:126:in readline' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:911:inrecv_response’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:
111:in do_start' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:921:incritical’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:
111:in do_start' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:525:instart’
c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/
action_mailer/base.rb:681:in perform_delivery_smtp' c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/ action_mailer/base.rb:523:insend
c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/
action_mailer/base.rb:523:in deliver!' c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/ action_mailer/base.rb:429:indeliver’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:76:in
`send_email’

Here is the Stack trace…

c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:135:in sysread' c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:135:inrbuf_fill’
c:/ruby-1.8.7/lib/ruby/1.8/timeout.rb:62:in timeout' c:/ruby-1.8.7/lib/ruby/1.8/timeout.rb:93:intimeout’
c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:134:in rbuf_fill' c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:116:inreaduntil’
c:/ruby-1.8.7/lib/ruby/1.8/net/protocol.rb:126:in readline' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:911:inrecv_response’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:
111:in do_start' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:921:incritical’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:
111:in do_start' c:/ruby-1.8.7/lib/ruby/1.8/net/smtp.rb:525:instart’
c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/
action_mailer/base.rb:681:in perform_delivery_smtp' c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/ action_mailer/base.rb:523:insend
c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/
action_mailer/base.rb:523:in deliver!' c:/ruby-1.8.7/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/ action_mailer/base.rb:429:indeliver’
D:/rails/india/pistachio/pistachio/app/controllers/send_email.rb:76:in
`send_email’

I m facing the same problem…
if u know the solution, kindly reply me

thanks in advance.
shranu