perplexityjeff / PowerShell-MailScanner

This is a PowerShell script to query a MailScanner database using the MySQL .NET Connector to retrieve mail entries from the database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PowerShell-MailScanner

This is a PowerShell script to query a MailScanner database using the MySQL .NET Connector to retrieve mail entries from the database based on various filters to query and end up with just the data you want.

Usage

You can of course always use Get-Help .\Get-MailScan to get examples or help but the most general usage of the script could be as follows.

Example that retrieves all mail entries that are marked as Spam and only from Today that are in the database.

./Get-MailScan -Server 127.0.0.1 -UserName user -Password example -Spam -Today

Use Format-Table, Select-Object and Get-Member to get the table how you want it.

Options

-LastWeek Default filter to query for mail between today and last week
-Today Default filter to query for mail that arrived today
-Virus Default filter to query for mail that was detected as a virus
-Spam Default filter to query for mail that was detected as a spam
-NotSpam Default filter to query for mail that was detected as a non-spam
-To Default filter to query for mail based on a To address this contains wildcards
-From Default filter to query for mail based on a From address this contains wildcards
-ToDomain Default filter to query for mail based on a mail domain
-Subject Default filter to query for mail based on the subject line of a mail

Prerequisites

The script looks by default on location C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.23\Assemblies\v4.5.2\MySql.Data.dll however using -MySQLPath you can change it if you like.

  • Remote Access to the MySQL or MariaDB database using a good secured user that can only Select.

Learning

I am still learning PowerShell and I do it mainly by just working as a day to day sysadmin. Please keep that in mind when viewing or using this script. I am open to pull requests to improve the project of course.

Credits

The idea came by a post found on the mailscanner mailing list found here.

http://lists.mailscanner.info/pipermail/mailscanner/2010-June/095932.html

References

https://www.mailscanner.info/

http://mailwatch.org/

http://lists.mailscanner.info/pipermail/mailscanner/2010-June/095932.html

https://dev.mysql.com/downloads/connector/net/8.html

https://www.cogmotive.com/blog/powershell/querying-mysql-from-powershell

About

This is a PowerShell script to query a MailScanner database using the MySQL .NET Connector to retrieve mail entries from the database.

License:MIT License


Languages

Language:PowerShell 100.0%