![]() |
||||||
|
This page was last modified: December 16 2007 16:43:05 | |||||
Sending local mailI often develop PHP projects locally on my laptop. These applications often send mail in various situations. While developing and testing it's very easy to accidently send mail to unintended recipients. The solution I came up with, is actually quite simple. First change the email addresses of all the users in the underlying database of the application. I does not matter what you put in front of the @ in the addresses, but they must all be at the same domain. After that you create a wildcard alias in Sendmail with the same domain, and point it to a local account. If you're not following me, don't worry. It will all make sense later. Let's setup a wildcard alias in Sendmail: # cd /etc/mail/ Open the text file virtusertable and add the following line: @some.domain.tld local_user Replace some.domain.tld with a domain you know and local_user with a local user. For example, I have a domain called nerdgirl.dk and the local user on my laptop is named fiona. Therefore the line in my virtusertable file looks like this:@test.nerdgirl.dk fiona IMPORTANT! It really does not matter what domain you use. But Sendmail will ignore the wildcard alias, if you don't provide a domain. The mail will never leave your computer. But if by some freak accident the mail is shipped of to world-wide-web, it's better that the receiving end is a domain of your own. After editing virtusertable, you need to run this command: # makemap hash virtusertable.db < virtusertable Next open the file local-host-names (which is in the same directory) and add the domain you have chosen: some.domain.tld Then restart Sendmail: # cd /etc/rc.d/init.d/ # ./sendmail restart Make sure it works as intended (the below command will pretend to send an email, not actually do it):
# sendmail -bv 123@some.domain.tld On my laptop, it would look like this:
# sendmail -bv 123@test.nerdgirl.dk The output of the command tells us that the mail would be send to 123@test.nerdgirl.dk using a local mailer with fiona as the receiving account. It all looks well, so let's try and do it for real. The below example would send a mail containing the current date: # date | mail 123@some.domain.tld The last thing you need to do, is providing the database with some email accounts (REMEMBER to replace some.domain.tld with the one you chose to use): mysql> update TABLE set EMAIL_FIELD = concat(UNIQUE_FIELD,'@some.domain.tld'); Make sure to change TABLE, EMAIL_FIELD and UNIQUE_FIELD to reflect your table structure. That's basically it! Like this you can test any application with mail functionality, without any worries. In Evolution the mail will be available in the account you have setup to read local mail.. |
||||||