Using Postfix to send out emails from development environment in Rails

Problem

You want to be able to send emails from your development enironment using Postfix in your (K)Ubuntu pc.

Solution

First you would need to install postfix:

sudo apt-get install postfix

and then you would need to change an option in postfix to not use tls, so change /etc/postfix/main.cf:

sudo vi /etc/postfix/main.cf

and change the smtpd_use_tls from yes to no:

smtpd_use_tls=no

restart your postfix server:

sudo /usr/sbin/postfix reload

and then setup your config/development.rb as follows:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:                 "127.0.0.1",
  port:                    25,
  enable_starttls_auto:    false
}

Command line mail message with postfix in (K)ubuntu

Problem

You have installed postfix in your local development machine (sudo apt-get install postfix), and you want to test sending emails from the command line using mail email_address@someone.com

 

Solution

You would first need to install the mailutils package:

sudo apt-get install mailutils

then you can send an email by:

mail email_name@example.com
CC: (leave blank)
Subject: Test subject
Main message body

and you can send it by pressing Ctrl+D

Redirecting postfix email to a different email account

Problem

You have setup your Rails app to send out emails using postfix, but you also want to redirect the incoming emais to a different account.

Solution

Edit the postfix configuration file vi /etc/postfix/main.cf and add the following two lines at the bottom:

virtual_alias_domains = outgoing_domain.com
virtual_alias_maps = hash:/etc/postfix/virtual

And then add the redirections to the virtual file with vi /etc/postfix/virtual:

outgoing_email@outgoing_domain.com           other_account@other_domain.com
@outgoing_domain.com                         other_account@other_domain.com

Then run the following two commands to restart postfix:

postmap /etc/postfix/virtual
postfix reload

* Based on the post here