Fly like a G Mailer

11 Nov

Bad rap references aside, no I do not listen to rap to all those wondering, I am referring to the “rails generate mailer” or “rails g mailer” command.  Up until today I didn’t know Mailer was the same class citizen as a Controller, Model, or Migration.  That is illustrious company and I feel like a moron considering I haven’t had knowledge of this before, guess I should RTFM.

Let me set the stage, like most web apps you have a Sign Up page and then you need to obviously communicate to this new fledgling user and usually that communique is over email.  I know rails has a gem for everything so I started searching and to my amazement it is built in!  You need to do some light configuration in your environment files and you are off to the races.  From there you basically create views (one with a .text suffix to handle those archaic email system) and it just works with a simple “.deliver” command.

Note those people not using Rails 3 you have to use the funky syntax of deliver_(your email name), you know those rails’y dynamic method calls that just don’t sit well with me but that is for another day.  Also if you are send a million emails you want to use a Delayed Job so you don’t cause a traffic jam on the web side.  It is that simple and I am off to building more features.  Today Rails won.

For those who want more details, here is the step by step that I followed and one here for Heroku.

 

Bonus Content:  I ran into some issues with the configuration of the smtp_settings.  Specifically the error was OpenSSL::SSL::SSLError (hostname was not match with the server certificate.  Above is not a typo, incorrect English and all, this is the error message. The issue is fairly common, it is talked about here, and it has to do with Rails Mailer defaulting to a encrypted connection or SSL, which my dev box shockingly doesn’t have its own SSL cert.  The fix is simple, you jump into your development.rb, staging.rb and production.rb too depending on your configuration, and tack :enable_starttls_auto => false on the ActionMailer::Base::smtp_configuration. I also want to point out, you need to make sure to restart your server for these changes to take place, ask me how I know.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.