<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Godbit Discussion Forum - Actionmailer with GMail SMTP server]]></title>
		<link>http://godbit.com/forum/viewtopic.php?id=876</link>
		<description><![CDATA[The most recent posts in Actionmailer with GMail SMTP server.]]></description>
		<lastBuildDate>Wed, 01 Nov 2006 18:13:29 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Actionmailer with GMail SMTP server]]></title>
			<link>http://godbit.com/forum/viewtopic.php?pid=10593#p10593</link>
			<description><![CDATA[<p>No problem.&nbsp; I&#039;ve asked many questions on this forum and received some great answers.&nbsp; It&#039;s always good to pass on something good&nbsp; when it works.</p><p>Zack</p>]]></description>
			<author><![CDATA[dummy@example.com (zreed20)]]></author>
			<pubDate>Wed, 01 Nov 2006 18:13:29 +0000</pubDate>
			<guid>http://godbit.com/forum/viewtopic.php?pid=10593#p10593</guid>
		</item>
		<item>
			<title><![CDATA[Re: Actionmailer with GMail SMTP server]]></title>
			<link>http://godbit.com/forum/viewtopic.php?pid=10573#p10573</link>
			<description><![CDATA[<p>Thank you!!!&nbsp; Saved me a good bit of time here...</p>]]></description>
			<author><![CDATA[dummy@example.com (tomrossi7)]]></author>
			<pubDate>Tue, 31 Oct 2006 21:07:04 +0000</pubDate>
			<guid>http://godbit.com/forum/viewtopic.php?pid=10573#p10573</guid>
		</item>
		<item>
			<title><![CDATA[Actionmailer with GMail SMTP server]]></title>
			<link>http://godbit.com/forum/viewtopic.php?pid=6771#p6771</link>
			<description><![CDATA[<p>I&#039;ve been trying to send emails with my gmail account for a while now, and thought I would share with you the working solution.</p><p>Turns out GMail supports only SSL SMTP mailing service, meaning if you cannot create a SSL connection to its SMTP server, you cannot send email through them. My Rails and Ruby (1.84) version do not yet support creating a SSL SMTP connection through Net::SMTP. DHH wrote about how to do so through installing msmtp, but&nbsp; I&#039;d rather not use another application if I don&#039;t have to.</p><p>The dynamic nature of Ruby allows me to enhance the functionality of that class.&nbsp; I found the following answers from Stephen Chu&#039;s and a Japanese site, <a href="http://d.hatena.ne.jp/zorio/20060416">http://d.hatena.ne.jp/zorio/20060416</a> .</p><p>You must paste some files in your vendor/plugins directory...</p><p>vendor/plugins/action_mailer_tls/init.rb<br /></p><div class="codebox"><pre><code>require_dependency &#039;smtp_tls&#039;</code></pre></div><p>vendor/plugins/action_mailer_tls/lib/smtp_tls.rb<br /></p><div class="codebox"><pre><code>require &quot;openssl&quot;
require &quot;net/smtp&quot;

Net::SMTP.class_eval do
  private
  def do_start(helodomain, user, secret, authtype)
    raise IOError, &#039;SMTP session already started&#039; 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 &#039;openssl library not installed&#039; 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(&#039;STARTTLS&#039;)
  end

  def quit
    begin
      getok(&#039;QUIT&#039;)
    rescue EOFError
    end
  end
end</code></pre></div><p>And your config/environments/development.rb or test.rb or production.rb, in your ActionMailer::Base&#039;s server settings if you have:</p><div class="codebox"><pre><code>ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
  :address =&gt; &quot;smtp.gmail.com&quot;,
  :port =&gt; 587,
  :domain =&gt; &quot;mycompany.com&quot;,
  :authentication =&gt; :plain,
  :user_name =&gt; &quot;username&quot;,
  :password =&gt; &quot;password&quot;
}</code></pre></div><p>If you call your ActionMailer::Base&#039;s deliver method, it will send an email through GMail. That took me a little time to work through yesterday, so hopefully this can save someone some time.</p>]]></description>
			<author><![CDATA[dummy@example.com (zreed20)]]></author>
			<pubDate>Thu, 06 Jul 2006 11:09:04 +0000</pubDate>
			<guid>http://godbit.com/forum/viewtopic.php?pid=6771#p6771</guid>
		</item>
	</channel>
</rss>
