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?
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:
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:
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 email@example.com, then your /etc/aliases would have this entry in it somewhere:
Once done, as root, run this command:
Now bounce your mail server as root:
Now when your PHP code sends a message of any address at from.com (doesn't matter which) to firstname.lastname@example.org, 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 email@example.com, and pick them up with Evolution quite easily.
A faster answer than what I came up with on Sept 24, 2010 is:
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:
Add in "joe: dev" if the account you login to Ubuntu is "dev" and the person you want to test sending mail to is firstname.lastname@example.org.
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 email@example.com if "dev" is your Ubuntu login.
At this point your PHP code can email to firstname.lastname@example.org, 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.