<?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>Gulics.com &#187; Dreamhost</title>
	<atom:link href="http://blog.gulics.com/category/dreamhost/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gulics.com</link>
	<description>Metal, Movies, Web Development, and More</description>
	<lastBuildDate>Wed, 29 Jun 2011 14:42:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>ActionMailer, DreamHost and &#8220;hostname was not match with the server certificate&#8221;</title>
		<link>http://blog.gulics.com/2009/03/22/actionmailer-dreamhost-and-hostname-was-not-match-with-the-server-certificate/</link>
		<comments>http://blog.gulics.com/2009/03/22/actionmailer-dreamhost-and-hostname-was-not-match-with-the-server-certificate/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 23:46:15 +0000</pubDate>
		<dc:creator>Stephen Gulics</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web of Metal]]></category>
		<category><![CDATA[ActionMailer]]></category>

		<guid isPermaLink="false">http://blog.gulics.com/?p=11</guid>
		<description><![CDATA[Today I wanted to add a simple Suggestion Box to Web of Metal. I planned out about 2 hours of my Sunday since the only unknown that I thought I would have to deal with was setting up the ActionMailer for Dreamhost. A quick google search and I found a simple post on Dreamhost&#8217;s Wiki. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I wanted to add a simple Suggestion Box to <a href="http://www.webofmetal.com" target="_blank">Web of Metal</a>. I planned out about 2 hours of my Sunday since the only unknown that I thought I would have to deal with was setting up the ActionMailer for Dreamhost.</p>
<p>A quick google search and I found a simple post on Dreamhost&#8217;s <a href="http://wiki.dreamhost.com/ActionMailer" target="_blank">Wiki</a>. So I configured my settings locally and successfully sent the email. These are the settings that I used:</p>
<pre name="code" class="ruby">
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address          =&gt; 'mail.domain.com',
:port                =&gt; 25,
:domain           =&gt; 'domain.com',
:user_name        =&gt; 'mailer@domain.com',
:password         =&gt; 'password',
:authentication   =&gt; :login,
}
</pre>
<p>After adding the settings to my environment.rb I did a quick test and everything worked. &#8220;Great!&#8221; I said, so now lets move the code to Dreamhost. And that&#8217;s were it all went downhill.</p>
<p>The functionality did not work in production. I looked at the logs and found the following error in the log:</p>
<pre>HomeController:rescue_action_without_handler:hostname was not match with the server certificate</pre>
<p>Ugh. To make a long story short it looks like a problem in Rails 2.2.2 with SSL  on the mailserver. It seems that Rails 2.2.2 automatically turns on something called STARTTLS if your using Ruby 1.8.7 and your SMTP server supports STARTTLS. Well I guess Dreamhost&#8217;s SMTP server supports it because it&#8217;s definitely turned it on. According to Dan Ryan in this <a href="http://rails.lighthouseapp.com/projects/8994/tickets/1491-ssl-problem-with-smtp-in-222" target="_blank">post </a></p>
<blockquote><p>&#8220;You&#8217;ll see this error if your mailserver has an SSL certificate set up for a hostname other than the one to which you are trying to connect. I was experiencing the same error, until I changed my smtp_settings to reflect the hostname of the associated SSL cert.&#8221;</p></blockquote>
<p>This issue is going to be <a href="http://rails.lighthouseapp.com/projects/8994/tickets/1731" target="_blank">fixed</a> in Rails 2.3 but since I am using 2.2.2, I needed a way to turn it off now. I guess I could of wrote a plugin using the information found in the <a href="http://rails.lighthouseapp.com/projects/8994/tickets/1491-ssl-problem-with-smtp-in-222" target="_blank">post</a> above but I found it just as easy to  modify the Rails code. I know, that is a bad practice but I did not feel like wasting any more of my time and my Sunday with this issue. Since Rails is frozen in my vendor directory I just modified vendor/rails/lib/action_mailer/base.rb</p>
<pre class="brush: ruby;">
def perform_delivery_smtp(mail)
  destinations = mail.destinations
  mail.ready_to_send
  sender = mail['return-path'] || mail.from
  smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
  # Comment out the following to fix the &quot;hostname was not match with the server certificate&quot;
  # smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto)
  smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
  smtp_settings[:authentication]) do |smtp|
  smtp.sendmail(mail.encoded, sender, destinations)
end
</pre>
<p>Hope this helps anyone else having the issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gulics.com/2009/03/22/actionmailer-dreamhost-and-hostname-was-not-match-with-the-server-certificate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

