<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>雪道屋 &#124; Snow on rails blog &#187; smtp</title>
	<atom:link href="http://blog.snowonrails.com/tags/smtp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.snowonrails.com</link>
	<description>life.each{&#124;day&#124; day.live_well!}</description>
	<lastBuildDate>Thu, 11 Feb 2010 07:03:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using GMail smtp server in rails app</title>
		<link>http://blog.snowonrails.com/2007/12/04/using-gmail-smtp-server-in-rails-app/</link>
		<comments>http://blog.snowonrails.com/2007/12/04/using-gmail-smtp-server-in-rails-app/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 08:16:00 +0000</pubDate>
		<dc:creator>snow</dc:creator>
				<category><![CDATA[action_mailer]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">urn:uuid:fe563242-ff6b-4afe-aa70-2dbfcb5b0ef8</guid>
		<description><![CDATA[&#30001;&#20110;action_mailer&#26412;&#36523;&#24182;&#19981;&#25903;&#25345;tls&#25110;&#32773;ssl&#30340;&#38142;&#25509;&#26041;&#24335;&#65292;&#32780;gmail&#30340;smtp server&#21448;&#35201;&#27714;tls&#25110;&#32773;ssl&#26041;&#24335;&#39564;&#35777;&#29992;&#25143;&#21517;&#21644;&#23494;&#30721;&#65292;&#25152;&#20197;&#25105;&#20204;&#38656;&#35201;hack action_mailer&#35753;&#20182;&#25903;&#25345;tls/ssl&#12290;&#22312;&#32593;&#19978;&#25214;&#21040;&#19968;&#31687;&#24456;&#26377;&#29992;&#30340;&#25991;&#31456;&#65306;http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html
&#30001;&#20110;&#26377;&#21487;&#33021;&#38142;&#25509;&#22312;&#22269;&#20869;&#27809;&#21150;&#27861;&#25171;&#24320;&#25152;&#20197;&#23558;&#20869;&#23481;&#19968;&#24182;&#36716;&#19979;&#26469;&#65292;&#20197;&#22791;&#26085;&#21518;reference:
Rail&#8217;s ActionMailer was simply the automatic choice, since I am building a rails app.
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 [...]]]></description>
			<content:encoded><![CDATA[<p>&#30001;&#20110;action_mailer&#26412;&#36523;&#24182;&#19981;&#25903;&#25345;tls&#25110;&#32773;ssl&#30340;&#38142;&#25509;&#26041;&#24335;&#65292;&#32780;gmail&#30340;smtp server&#21448;&#35201;&#27714;tls&#25110;&#32773;ssl&#26041;&#24335;&#39564;&#35777;&#29992;&#25143;&#21517;&#21644;&#23494;&#30721;&#65292;&#25152;&#20197;&#25105;&#20204;&#38656;&#35201;hack action_mailer&#35753;&#20182;&#25903;&#25345;tls/ssl&#12290;&#22312;&#32593;&#19978;&#25214;&#21040;&#19968;&#31687;&#24456;&#26377;&#29992;&#30340;&#25991;&#31456;&#65306;http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html</p>
<p>&#30001;&#20110;&#26377;&#21487;&#33021;&#38142;&#25509;&#22312;&#22269;&#20869;&#27809;&#21150;&#27861;&#25171;&#24320;&#25152;&#20197;&#23558;&#20869;&#23481;&#19968;&#24182;&#36716;&#19979;&#26469;&#65292;&#20197;&#22791;&#26085;&#21518;reference:</p>
<p>Rail&#8217;s ActionMailer was simply the automatic choice, since I am building a rails app.</p>
<p>Turns out GMail supports only <span class="caps">SSL SMTP</span> mailing service, meaning if you cannot create a <span class="caps">SSL</span> connection to its <span class="caps">SMTP</span> server, you cannot send email through them. My Rails and Ruby (1.84) version do not yet support creating a <span class="caps">SSL SMTP</span> connection through Net::SMTP. <span class="caps">DHH</span> writes about how to do so through installing msmtp here, but we developers just obviously love options =)</p>
<p>The dynamic nature of Ruby allows me to enhance the functionality of that class. I found the following code from a couple Japanese posts here and here on the web (fairly low Google ranking). Pasting them in my /vendor/plugins as follow:</p>
<p>$ cat vendor/plugins/action_mailer_tls/init.rb<br />
require_dependency &#8216;smtp_tls&#8217;</p>
<p>$ cat vendor/plugins/action_mailer_tls/lib/smtp_tls.rb<br />
require &#8220;openssl&#8221;<br />
require &#8220;net/smtp&#8221;</p>
<p>Net::SMTP.class_eval do<br />
  private<br />
  def do_start(helodomain, user, secret, authtype)<br />
    raise IOError, &#8216;SMTP session already started&#8217; if @started<br />
    check_auth_args user, secret, authtype if user or secret<br />
end</p>
<pre><code>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
ensure
  unless @started
    # authentication failed, cancel connection.
      @socket.close if not @started and @socket and not @socket.closed?
    @socket = nil
  end
end</code></pre>
<pre><code>check_response(critical { recv_response() })
do_helo(helodomain)</code></pre>
<pre><code>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)</code></pre>
<pre><code>authenticate user, secret, authtype if user
@started = true</code></pre>
<pre><code>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</code></pre>
<pre><code>def starttls
  getok('STARTTLS')
end</code></pre>
<pre><code>def quit
  begin
    getok('QUIT')
  rescue EOFError
  end
end</code></pre>
<p>So now, in your ActionMailer::Base&#8217;s server settings if you have:</p>
<p>ActionMailer::Base.server_settings = {<br />
  :address =&gt; &#8220;smtp.gmail.com&#8221;,<br />
  :port =&gt; 587,<br />
  :domain =&gt; &#8220;mycompany.com&#8221;,<br />
  :authentication =&gt; :plain,<br />
  :user_name =&gt; &#8220;username&#8221;,<br />
  :password =&gt; &#8220;password&#8221;<br />
}</p>
<p>You call your ActionMailer::Base&#8217;s deliver method (perhaps from a custom subclass), it will send an email through GMail. Mission accomplished.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.snowonrails.com/2007/12/04/using-gmail-smtp-server-in-rails-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
