I'm a PHP web developer. I need to set up my Ubuntu workstation (10.04.1 LTS) so that I can debug mail without it really going out to the WWW. So, I need to work with pretend domains like from.com and to.com. What is the fastest, shortest, easiest way that I can configure PHP to enable outgoing mail that stays only on my server, and then receive this mail using Evolution?
2 Answers
Ubuntu comes with Sendmail by default, which can cause you to rip your hair out in my opinion. Postfix appears somewhat easier to configure. So, I did this:
sudo su
apt-get --purge remove sendmail
apt-get --purge remove sendmail-base
apt-get --purge remove sendmail-cf
apt-get install procmail
The procmail will install Postfix by default.
When the Postfix install runs, it will automatically show a blue screen where you need to select the install type. Choose Local Only.
Next, edit /etc/postfix/main.cf and set mydestination parameter so that it contains a comma-delimited list of domains for your from and to, such as:
mydestination = localhost, localhost.localdomain, from.com, to.com
Next, edit /etc/aliases as root. So, if your user account in Ubuntu (the one you login with) is dev, and you want to send test mail as a programmer to jack@to.com, then your /etc/aliases would have this entry in it somewhere:
jack: dev
Once done, as root, run this command:
newaliases
Now bounce your mail server as root:
/etc/init.d/postfix stop
/etc/init.d/postfix start
Now when your PHP code sends a message of any address at from.com (doesn't matter which) to jack@to.com, your mail server will automatically put it into a file /var/spool/mail/dev.
So, how to go read it? Well, I don't particularly like Evolution over Thunderbird, but it seemed to be more configurable for this task. I opened it up and added a new account. In there, I added dev@localhost and then chose Local Delivery. On that file path, I chose /var/spool/mail/dev. On sending mail, I chose Sendmail even though I don't have that installed anymore. I mean, I'm not caring about sending mail back from my inbox to the mail server, just receiving it so that I can debug the messages and ensure the mail will work properly. However, you can choose a different outgoing mail server config if you want. Anyway, from there, I clicked OK, and then I clicked the Send/Receive button to download new messages.
At that point, I could send messages out of PHP to an account jack@to.com, and pick them up with Evolution quite easily.

- 1,518
- 2
- 14
- 35
-
1I realize this is an old post but should joe: dev be jack: dev? – Jesse Nov 14 '11 at 20:49
A faster answer than what I came up with on Sept 24, 2010 is:
# apt-get install sendmail
# vim /etc/hosts
Comment out the 127.0.1.1 line with # symbol and then move what follows it after 127.0.0.1. Also, ensure that localhost, localhost.localdomain, from.com, and to.com are on that 127.0.0.1 line. For instance, on my workstation my two lines look like so:
127.0.0.1 localhost.localdomain localhost dev-laptop from.com to.com
#127.0.1.1 dev-laptop
Now continue...
# vim /etc/aliases
Add in "joe: dev" if the account you login to Ubuntu is "dev" and the person you want to test sending mail to is joe@to.com.
# newaliases
# /etc/init.d/sendmail restart
# /etc/init.d/apache2 restart
In Evolution, select Standard Unix mbox spool file (the default sendmail format) and point to /var/spool/mail/dev if your login to Ubuntu is "dev". For outgoing mail, choose "sendmail". On what mail to pickup, set it as dev@from.com if "dev" is your Ubuntu login.
At this point your PHP code can email to jack@to.com, and be able to pick them up in Evolution quite easily. This is great for debugging your PHP web apps locally on your Ubuntu workstation.

- 1,518
- 2
- 14
- 35