Monday, February 25, 2008

Using Google to send mails from Rails

I was using 'sendmail' for sending mails from my web applications. The apps was sending mails for welcome messages, comment notifications, activation mails, send to a friend and all other features depending on sending emails to the application user. But recently, I was deploying a webapp on a server in which sendmail is not configured correctly. I didn't have time and wouldn't like to invest any time on system administration then, so I searched for another solution for my webapps to send mails through Google. I found ssmtp. It is a simple tool doing a simple task, sending mails. However it does not receive mail, expand aliases or manage a queue. It is just forwarding mails to the mailhost. SSMTP requires replacing 'sendmail'.

There is nothing required from Rails app to use ssmtp, actually it was transparent. Just make sure that the ActionMailer is configured to use sendmail.
ActionMailer::Base.delivery_method = :sendmail
SSMTP Installation
In Ubuntu I use apt-get to install the package. I am enabling all the sources on my ubuntu, so you may need to do so. In RPM based distribution like Centos in my case i used this link to download the required RPM.

on Centos
sudo wget
sudo rpm -ivh ssmtp-2.61-11.4.el5.i386.rpm
on Ubuntu.
sudo apt-get install ssmtp

SSMTP Configuration

SSMTP configuration files lie in /etc/ssmtp so you need to edit the conf file and fill it with the your gmail account.
There is one feature you will get by using Google as your SMTP server, it's its sent mail folder which archive every mail sent by your application, this feature being a bless or damn is up to your needs.

Related links:

1 comment:

Reuben said...

thanks for the blog post. Your post along with others helped me figure out my email problems.


JavaScript bloat is a more real problem today than it ever was. Bundlephobia lets you understand the performance cost of adding a npm pack...