From: Junkone Date: 2008-06-22T18:48:32+09:00 Subject: Re: Using actionmailer to send an email On Jun 22, 5:47 am, Junkone wrote: > On Jun 21, 8:45 am, Phlip wrote: > > > > > APNelson.L wrote: > > > so how would I go about writing a scrip to send an email then? > > > You might have some small hope of installing a lite POP3 server on your own > > workstation. Then you can test ActionRecord by sending it mail. > > > I tried that once, and I could not find a POP3 server that was _lite_, like > > a student's sketch of one. They were all real servers, top-heavy and > > configuration-hostile. > > > Then turn on TLS security, to emulate how GMail does it... > > > -- > >   Phlip > >  http://assert2.rubyforge.org/assert_yin_yang.html- Hide quoted text - > > - Show quoted text - you have to add this piece of code for gmail smtp to work thro action mailer INSTALL THE FOLLOWING AS smtp_tls UNDER C:\ruby\lib\ruby\gems\1.8\gems \actionmailer-2.0.2\lib ############## START OF CODE ################################## 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) 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 end end end ##########END OF CODE #############################################