Mailing error in Rails 2.3.2

Siddu
Thu, 09 Apr 2009 13:04:23 -0000

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 = ''login@somedomain.com''
    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= ''login@somedomain.com''
@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.................



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---