»Saturday, February 21, 2009

HOWTO: How send email using Gmail or Google Apps from Rails

If you are developing a Rails application that needs to send email, you probably want to have support for sending emails without having sendmail or an smtp server installed on every development machine.

Everyone who has a Gmail account has access to their SMTP server for free, but there are some caveats:

1. Google only allows secure SMTP connections and Rails does not have support for this out-of-the-box.
2. Even if you solve problem #1, you do not want to embed your gmail password in your code.

Let's solve Issue #2 first: There are two immediate solutions

1. Create a throwaway gmail account just for your rails project.
2. Configure one of your domains for Google Apps, and create an email address purely for your Rails development (Google allows upto 200 email addresses in the free version). You can embed this username and password in your application and not worry about other folks having access to it.

Now about Issue #1:

There's a hack called 'smtp_tls' to enable secure SMTP access in Rails, but I've had trouble finding the original blog post that described this, even though that code is available in many different places. Here's an easy way to get it working.

1. Download 'smtp_tls' from here. (You can also google 'smtp_tls' to find it elsewhere) and copy it to your {RAILS_ROOT}/lib/

2. Edit {RAILS_ROOT}/config/environment.rb.
At the bottom of the file (after the very last line) add the following

require 'smtp_tls'

ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "yourdomain.com",
:authentication => :plain,
:user_name => "username@yourdomain.com",
:password => "yourpassword"
}


Of course, replace yourdomain.com with the domain where Google Apps is running, and username and yourpassword with the username and password that you created on that domain. Note that the :userame has to be your complete email address for Google Apps. You do not have to change the settings for :address and :port since the smtp server address does not depend on the domain that you configured Google Apps for. The :port parameter can be either 587 or 465.

If you are using a regular Gmail account, use that account's settings for ::user_name and :password.

You can find more information about Google's SMTP settings on their help page, but you wouldn't need anything more than what's described above.
That's it! In your code, use ActionMailer like you would normally do.

Labels: ,



...
»Sunday, August 03, 2008

Gringo...

From my friend Heather's recent trip to Chile.



Edit: Welcome Reddit Users!


...
»Sunday, May 11, 2008

Facebook Profile

Choosing your profile picture (from PhD Comics - extras included)




Original comic here.


Labels: , ,



...
»Friday, May 09, 2008

Ruby on Rails and mysql connection problems

If you are losing connection to mysql every so often on OSX (I'm using 10.5 Leopard), it's probably because you do not have the native C ruby-mysql bindings. If your error looks like this:
Mysql::Error: Lost connection to MySQL server during query:


then try the following. Verify that the bindings are really not present. In a terminal window, open up the interactive ruby shell and type the following commands:
irb
>> require 'mysql.bundle'
=> true
>> exit


If you do not get 'true', then you need the bindings. Back to your terminal window and type the following:
$ sudo -s
$ ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql


Try require 'mysql.bundle' again and this time you should get back true.

Sources: 1 and 2.

Labels: , , , ,



...
»Saturday, May 03, 2008

Grounds for your garden

Did you know that you can get coffee grounds for free from any Starbucks? Just walk in and ask for 'Grounds for your Garden' and you will receive a huge bag of used coffee grounds that you can use to dress up your soil. If you live in Arizona, you probably need some acidity in your soil anyway, so try it out!


...
»Monday, April 14, 2008

Aim for Fame

From Banksy's guide to cutting stencils:

Any fame is a bi-product of making something that means something. You don't go to a restaurant and order a meal because you want to have a shit.


...
»Sunday, February 10, 2008

The economy is growing... so what?

I don't think there's any way to summarize this post, so just go ahead and read it. Bloody brilliant!


...

HOWTO: Carry on a multi-lingual conversation using Google Talk

I've always been a fan of Google's language tools, especially when I'm trying to find out how to say a phrase in Spanish. Now Google has built a bot out of the tool so that you can actually chat to it using Google Talk (or any jabber client) and receive the translation in real time.

Here's how to use it: Simply add en2es@bot.talk.google.com to your friend list and chat with the bot to automatically translate from english to spanish. Google has a list of currently supported language codes, but you can always try out a code to see if it has been implemented. (The current list is ar2en, de2en, de2fr, el2en, en2ar, en2de, en2el, en2es, en2fr, en2it, en2ja, en2ko, en2nl, en2ru, en2zh, es2en, fr2de, fr2en, it2en, ja2en, ko2en, nl2en, ru2en, zh2en)

Now, let's say that you are trying to talk to a Spanish speaking person over chat and neither of you are particularly good at the other language. You carry on a perfectly usable conversation by following these steps:

1. Add en2es@bot.talk.google.com to your friends list.
2. Add the reverse, i.e. es2en@bot.talk.google.com as a friend.
3. Invite both the bots to a group chat. Also, add your spanish speaking friend to the chat.

Now, everything that is said in English will be translated to spanish by the en2es bot. Also, everything that's said in Spanish will be translated automatically by es2en. (Don't worry, there will not be any infinite loops)

This is fully scalable - add all kinds of other language bots (and the reverse bots) to have a wickedly cool group chat!

Happy chatting!

Labels: , , ,



...
»Sunday, January 06, 2008

The catch-all "World Music" category

If you have ever tried to buy Indian music from one of the popular (and legitimate) online music stores in the US, then good luck finding the albums you want. Even though Indian music has enough genres and languages to have more categories than western music, it is always relegated to the catch-all 'World Music' category.

It's understandable the stores don't normally categorize international music since the market for that in the US is probably a fraction of the market for mainstream music, but for an online store like iTunes, creating proper sub-categories for international music does not increase their operational cost. Maybe we will get properly categorized music when iTunes hits more international markets.


...
»Thursday, December 20, 2007

Xmas for the child of an engineer

I got this in a forwarded email and I could not find out who created it (hence it's not attributed) but it's tough being born to a geek family.
Link (pdf)

Labels: ,



...

What to do next

Latest Photos

  • www.flickr.com
  • » View Gallery

Stuff I read