Installing SMTP on your server

Depending on the scale of your application, installing and maintaining a reliable emailing infrastructure can be a time consuming task. You might find it more practical to use a service like SendGrid, Postmark or Mandrill.

Installing Postfix

Postfix is a free and open-source mail transfer agent that routes and delivers electronic mail, and we’ll use it to set up your SMTP server.

Start by SSHing to your server and installing it:

$ sudo apt-get install postfix

The installation will ask you what type of installation you prefer - select Internet site. It will also ask you to input your domain name.

That’s it! You now have a SMTP server installed. We just need to make some configurations to start using it:

$ sudo nano /etc/postfix/main.cf

In the myhostname field, input your hostname:

myhostname = example.com

This one configuration is enough to have a functional SMTP server. Use deploy hooks to automate this procedure on any new servers you fire up through Cloud 66. You can go ahead and save and exit the configuration, and reload to put these changes into effect:

$ sudo /etc/init.d/postfix reload

You can confirm that the server is running by issuing nc localhost 25, and you can also send a test email with sendmail sample@example.com.

Once you enter the command, you can type your message and hit CTRL-D to send it.

Configuring Rails

Add the following code (or variation thereof) to your Rails application environments configuration to send email through this SMTP server:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.smtp_settings = {
  :address => "localhost",
  :port => 25,
  :domain => "example.com",
}

Still need help? Contact Us Contact Us