Solved

Temporary email address feature

Posted on 2010-09-15
4
529 Views
Last Modified: 2012-06-27
I am looking for some sample implementation for generating temporary email  addresses which are valid for a certain period of time.

i may be jumping ahead but i am looking for a php/ mysql based solution.

any comments or help is highly appreciated.

Thank you.
0
Comment
Question by:nainil
  • 2
4 Comments
 
LVL 11

Expert Comment

by:VanHackman
Comment Utility
Which e-mail server will you use?
Under which Operative system?
And by the way, What is the purpose of this "feature"?  probably there are another way to reach your goal, because there are many secutity issues related to what you want to do here.
0
 

Author Comment

by:nainil
Comment Utility
thank you VanHackman: I have my own servers which I am planning to use as a gateway. it is a linux box. I am primarily using this feature for my own use. I am vary of spam sent to my email.
0
 
LVL 11

Accepted Solution

by:
VanHackman earned 250 total points
Comment Utility
Well, this is very unusual, but anyway...

I think that you can get that type of feature using:  CRON + Zimbra + MySQL + Php

You should create an email account manager with php. This Account manager will be a interface where you can create New Email accounts, and store a register of all them into the MySQL DB.

For every Email account you should store the expiration date of it. So at this point you just set up a CRON Job that will execute a script  that will check the expiration date for every Email account in the table, when some Expiration date is over, the script delete the account.

In order to give to your Php Email account manager the hability of create/delete Email accounts you will need the exec() or the system() function. and an Email Server software that allow command line management, like Zimbra!.

So if you use Zimbra, the commandas that you will need are:

* createAccount:

Syntax:{name@domain} {password} [attribute1 value1 etc]
Type on one line.
zmprov ca joe@domain.com test123 displayName JSmith  

and

* deleteAccount:

Syntax:{name@domain|id|adminName}
zmprov da joe@domain.com

You can find more about Zimbra Commands here:

http://www.zimbra.com/docs/os/latest/administration_guide/A_app-command-line.13.3.html

Have Fun!
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
Here is how I would design it.  

Set up an email "pipe" script that receives all of the email sent to the domain.  The pipe script will parse the email messages and extract the "to" address.  You can look up this "to" address in your MySQL data base, and translate the temporary address into the permanent address.  You can discard anything that does not match a valid "to" address (this eliminates spam, as well as expired temporary addresses).  Then the pipe script can send the email to the translated, legitimate address.

You will need a couple of simple table maintenance scripts - you'll want to add the temporary email addresses to the data base table, and be able to delete them manually as well as having them expire.  A simple DATETIME column in the table will be enough to give you an expiration date.

Here is an email pipe script that I have used successfully.  Hopefully it can form a foundation for your code.  You will be able to access your data base just fine, but you may want to check carefully before you assume anything about the values in the PHP superglobal arrays - this does not run under the web server umbrella, and some things like DOCUMENT_ROOT are going to be different.

Best of luck with it, ~Ray
#!/usr/bin/php -q

<?php // /email_pipe/index.php



// THIS IS AN EMAIL PIPE SCRIPT.

// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.

// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION





// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?

// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org

// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.

// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:

// 1...5...10...15...20...25...

// |/home/{account}/email_pipe/index.php





// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG

// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755

// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX





// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE

// 1...5...10...15...20...25...

// #!/usr/bin/php -q

// <?php ... PROGRAM CODE FOLLOWS





error_reporting(E_ALL);



// USE THE OUTPUT BUFFER - THIS DOES NOT HAVE BROWSER OUTPUT

ob_start();



// COLLECT THE INFORMATION HERE

$raw_email = '';





// TRY TO READ THE EMAIL FROM STDIN

if (!$stdin = fopen("php://stdin", "R"))

{

    echo "ERROR: UNABLE TO OPEN php://stdin \n";

}



// ABLE TO READ THE MAIL

else

{

    while (!feof($stdin))

    {

        $raw_email .= fread($stdin, 4096);

    }

    fclose($stdin);

}





// REMOVE MULTIPLE BLANKS - AND OTHER PROCESSING AS MIGHT BE NEEDED (DB LOOKUP?, FORWARD TO "REAL" ADDRESS?)

$raw_email = preg_replace('| +|', ' ', $raw_email);





// PROOF OF CONCEPT: SPEW WHAT WE GOT, IF ANYTHING, INTO THE OUTPUT BUFFER

var_dump($raw_email);



// CAPTURE THE OUTPUT BUFFER AND SEND IT VIA EMAIL

$buf = ob_get_contents();

mail ('you@your.org', 'EMAIL PIPE DATA', $buf);

ob_end_clean();

Open in new window

0

Featured Post

Make managing Office 365 email signatures a breeze

Are you using Office 365? Having trouble trying to set up email signatures for your users? Getting stressed out managing multiple signatures? Need an easier way to manage? We have a solution for you, try the most-user friendly and powerful signature management tool on the market.

Join & Write a Comment

Microsoft goes to great lengths to ensure that the users don’t encounter issues while working with MS Outlook. But errors are inevitable and can occur when you least expect them. One of such errors which are encountered in Outlook is Error 0x800ccc1…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now