May 27, 2009

How to use GMail’s SMTP Server with Merb

I switched our email service provider to Google last week. So I have to figure out how to send out emails with GMail. I started with the default Net::SMTP settings, but it failed miserable:

    ~ 530 5.7.0 Must issue a STARTTLS command first. 7sm1765038qwf.45

After playing a while and googled a bit, here is the solution:

1. In your dependencies.rb, add following line:
    dependency "tlsmail"
2. Install the gem
    bin/thor merb:gem:install
3. Modify your init.rb
   
4. Over write the mailer
   
    Note: the "Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)"
5. Sending email
   
    Note: use :text instead of :body

Now, you are good to go.


No comments: