Perl Script to automatically put emails into a MySQL Database

Written by Kevin on September 13, 2012

I have written/highly modified a perl script to take piped in emails and insert them into a MySQL database. I accomplish this by having my MTA pipe them to this script. You can download the script from this Github Repo, or you can download it directly from here.

The Script

This script requires that you have Perl installed with the following Modules:

  • DBI
  • Email::MIME
  • Email::Address
  • HTML::Strip
To use this script, first replace the following items in the script:

  • DATABASE The name of the Schema/Database
  • SERVER The host of the MySQL Server. ex: localhost, 192.168.0.10, etc
  • USER The user of the MySQL database
  • PASSWORD The password of the MySQL user
Place the script on your server and make sure it is accessible and executable by your MTA. Set your MTA to pipe incoming emails to this script. That should be all that is needed.

GitHub Repo: https://github.com/mrkmg/email2mysql Original Script: http://www.blazonry.com/perl/mail2mysql.php