Tombuntu

Send Outgoing Email with Postfix

If you’re running a web application with user registration, you may need to have users or administrators receive email from the application. When you just need to send outgoing email and don’t need to receive, it’s easy to set up Postfix to do this for you. You can even set the “from” header so that replies will go to your own email account. This how-to was tested on Ubuntu 8.04 LTS server.

I’ve also written a post on sending mail using sSMTP which may be better suited for single user systems.

Install Postfix on your server:

sudo apt-get install postfix

During the installation of Postfix, you will be prompted to choose some settings for Postfix.

  1. For “type of mail configuration” select “Satellite system”.
  2. For “mail name” type the default domain name to use in outgoing emails.
  3. For “relay host”, set blank.

That’s all you need to send email with Postfix. Time to test it out:

sendmail EMAILADDRESS
FROM: FROMADDRESS
SUBJECT: hello world
this is a test email
.

The email will be sent to EMAILADDRESS with a reply address of FROMADDRESS. If this works, PHP’s mail() function should now also work.

For security, you should check that port 25 is still closed so nobody can connect to Postfix. This setup is working for me, but I’m no expert in Postfix or email and it’s possible you could have trouble with some spam filters rejecting mail sent this way without additional configuration.

Archived Comments

Farrukh Najmi

As I understand it, if I wish to send outgoing email from my local machine to my gmail address (or any other external address) I need an outgoing SMTP server. In my case my outgoing SMTP server requires authentication using my account credentials. How do I do that? Also, is there a way to avoid having to authenticate to send an outgoing message?

Thanks for the great blog.

Colan Schwartz

See this thread to learn how to tell Postfix your credentials for the remote SMTP server: http://askubuntu.com/questions/47609/how-to-have-my-php-send-mail

Anthony DeRosa

This worked for me on Ubuntu 10.04 LTS. I was able to send to a GMAIL account without it being treated as SPAM. I didn’t even have to mess with my domain’s SPF record.

Gennady

How to test this sendmail with some text file attachment? Thanks.

Alrik

Simple and effective. This solution work perfect.

Red

Worked. Thanks for the nice tip. You deserve a hug :)

Respond via email