Auto Save Emails to SQL Database

Discussion in 'Programming' started by damik, Mar 10, 2007.

  1. #1
    Anyone seen or written a script that will automatically save emails of a certain address directly into an SQL database?

    I reckon it would be a CGI script, maybe PHP, which would run via cron at intervals throughout the day. I also know wordpress has a similar feature which creates posts from emails, I guess I could dig into that as well.

    Any thoughts?

    Thanks!
     
    damik, Mar 10, 2007 IP
  2. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Grab a PHP script that reads from a POP3 account... you can find some at phpclasses.org.

    Step through the messages and save each one into an SQL database you have created... so the only work you have to do is matching things like title, sender, etc. to the columns of your database table.
     
    Robert Plank, Mar 10, 2007 IP
  3. damik

    damik Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Robert, PHP has been the answer, sort of. For those interested in such an app by using imap_open and imap_fetchbody you can fetch mail from your pop3 mail server from a PHP script, and then save it to a database or whereever you would like.

    The tricky part - and the part i'm still working on - is formatting/parsing the email message body. It's a complete nightmare trying to sort the line breaks after applying php's quoted_printable_decode function to the string.
     
    damik, Mar 10, 2007 IP