##Overview You might have a need for a temporary mail service like mailinator.com on your own machine. This guide provides the minimum required steps to do that. The setup we will use is as follows
Procmail (Receive mail and forward to script)--->PHP Script(Parse Mail and put in Database)--->MySQL(Store the mails)--->JSON
Note: This is intended as a quick DIY for simple projects. Hence, we will not go into more details like spam detection and memory optimization.
##Instructions ####Setup Infrastructure
- Get a Top level domain name (Note: Getting this to work with a sub-domain will require more work and setup)
- Change the MX record to point to the public IP of your machine
- Install mysql on your machine and setup a database to hold your mails.
- Create a table with all the fields you want. A few example fields can be Date, From, Subject, Body etc.
####Setup PHP Script
- Install php on your machine and php-mime-mail-parser. We will be using this library to parse the incoming mails.
- Write a simple file to parse emails from the stdin stream. You can look at the sample file of the library for this.
- You can store the extracted fields into your MySQL database.
- Install procmail and postfix
/etc/postfix/virtualfile and add the line
@yourdomain.com forward. This will send any mail addressed to any user on yourdomain.com to the user forward.
- In your
/new/aliasesfile, add a forward to your PHP file. This can be done like this ->
forward: "|/usr/bin/php -q /var/www/html/proc_mail.php"
newaliasesto update your aliases
- Edit the file at
/etc/postfix/main.cfand make this change
virtual_alias_maps = hash:/etc/postfix/virtual
- Restart postfix by running
service postfix reload
- You can see the incoming mails at /var/log/mail.log
- You can setup a simple php file to retrieve all the emails for a given id and provide the data through JSON.