Page 1 of 1

Getting POP->Reading Mail->insert in MYSQL

Posted: Wed Aug 07, 2002 5:26 am
by Christian S
Hi,
my problem, as you can see in the header, is that i need a script , which can get the mails of a pop account on the same server, getting the content of the mails, and writing them in a mysql database. The fields are normed, which means i´ve got Name: XXX, Email: XXX and so on. Anyone knows how to do it best, or even better knows where to get such a script ?
Thanks for the help
Christian

Posted: Wed Aug 07, 2002 5:34 am
by DesignerSMS
To do this you would need to connect to the POP3 server manually (using the socket functions), parse the mail message and then save the correct bits into the mySQL database.

Information on the POP3 protocol can be found at http://www.csl.sony.co.jp/cgi-bin/hyperrfc?rfc1081.txt.

Once you have the mail message I would suggest splitting it into separate lines because you have to separate the header from the message body.

A simplified version of an email message directly from a POP3 server looks something like this:

Code: Select all

Mail From: <user@host.com>
To: <receipient@otherhost.com>
Subject: This is a cool message.

The data goes here.
Notice how there is a blank line separating the header info and the message text.
You would need to parse the header one line at a time and get the fields you want to store separately in your database (e.g. From, To, Subject) and then place the rest of the message in the database as well.

There might be some scripts out there to help you do this (at least to interact with a POP3 server). Otherwise, happy coding.

:: Kondro ::

Posted: Wed Aug 07, 2002 5:34 am
by twigletmac
If you are looking for a script please try http://www.hotscripts.com .

Mac