tags:

views:

190

answers:

5

Hey there,

I have seen some web apps that allow me to email stuff to a special ID and it magically turns up in my account. How exactly do they do this?

+1  A: 

Without you giving an example of the specific service you're thinking of, it's hard to know exactly, but one way could be:

  • you give your email address to one of these sites, e.e. magic-mail.com

  • they insert this into their db, and take the db id value for this entry (12345)

  • they give you an address using this id ([email protected])

  • when mail is received by magic-mail.com, they look up the part before the @, pull out the associated email address for that ID, and relay the message on to the address you gave initially ([email protected])

There are many other ways of doing this, likely more simple than the above, but again, without examples it's hard to tell you exactly how the site you're thinking of is operating.


Edit

On reading the question, I assumed "my account" meant your mail account. If you meant an account you have on this company's system, then the process would be the same as the above, but changing the last step to:

  • when mail is received by magic-mail.com, they look up the part before the @, pull out the associated email address for that ID, and copy the contents of the message to the account associated with that id.
ConroyP
Yes, what stumps me is how I can read an incoming email from the inbox? Can I do it using a server side language like PHP?
PHP -> http://pear.php.net search for imap/pop3 access, http://www.php.net/imap. Python -> http://docs.python.org/library/imaplib.html
daniels
A: 

Yes, sorry for the generic nature of the question.. I did not quite know how to phrase it. So let me try again by giving a specific case of what I wish to do.

I have a website hosted on a standard hosting plan. So I have an email addy [email protected]. Now, I want to do this: When I send an email to this ID, I want a script to read its contents, and then copy the content to the DB.

Would I be able to do this using standard PHP, or do I need any special tools available from my web hosting side to be able to perform this task?

Thanks.

you should put this as an edit to your original question, not an answer.
Jason Miesionczek
If "standard hosting plan" means "shared hosting," then probably not. If you ssh and root access, then yes, its feasible, but you need to tell us what mail server you're running.
Richard Levasseur
A: 

You can write a simple script on python/php or any language your know. Make it recieve a pop mail for account '[email protected]' and put the content to db.

It is quite easy.

vpol
A: 

You would need a way to monitor the mail account for new messages, read the message format, parse out the parts that are important to you and then perform the insert.

Monitoring the mail account would require having a script running on the server in a specified interval, otherwise the only other way would be to access a certain URL manually which would access the mail account and do all the necessary processing.

Depending on your hosting provider and the amount of freedom they give you, this may or may not be possible.

Jason Miesionczek
A: 

Short way:
You need to write a script that will connect to mail server, fetch mails, parse them and then put to database.
Run this in a cron job and you're set.

daniels
Assuming that his web hosting gives him shell access..
Jason Miesionczek
Any cPanel / Plesk hosting provider offers support for CGI scripts and CRON jobs. And even without cgi he can make a normal php script and call it with curl/wget every now and then assuming he doesn't have tons of mail.
daniels
Cron jobs for cPanel/Plesk can be setup without shell access.
daniels