postfix

Setting up Postfix to use an external mail server

Sometimes sending mail to a dev account is all well and good, but if the mail server you are sending to is not accepting the mail for one reason or another (disallowed dynamic ip addresses, for instance) then you might need to set it up to send through a mail server (relay).

I am using smtp.tatedavies.com as an example here, and the user “frank” with his password being “penguin” (clearly a very high security password)

Fire up terminal and sudo in.

sudo su
postconf -e "relayhost=smtp.tatedavies.com"
postconf -e "smtp_sasl_auth_enable=yes"
postconf -e "smtp_sasl_password_maps=hash:/etc/postfix/smtp_password"
echo "smtp.tatedavies.com frank:penguin" > /etc/postfix/smtp_password
chmod 600 /etc/postfix/smtp_password
postmap /etc/postfix/smtp_password
service postfix restart

Setting up postfix on Ubuntu for mailing from PHP

To allow your Ubuntu server to send emails from PHP, then you need to install postfix. Postfix is a mailer for *nix platforms.

So, to install it:

sudo apt-get install postfix

When this is installing, you’ll need to enter some options, like what sort of server you’re connecting to. I use my companies details in here, and this means I need to enter the domain into the origins so that we don’t get refused mail.

sudo nano /etc/postfix/main.cf

Un-comment the line that states myorigin = /etc/mailname

Also, I have to enter the ip address of my mail server in the relayhost section.

CTRL X and save the file.

Now, we need to create the file /etc/mailname

sudo nano /etc/mailname

In this empty file, enter the domain name for your mailserver.

christatedavies.co.uk

CTRL X and save the file.

Now, just restart postfix:

sudo /etc/init.d/postfix restart

Job’s a goodun.