Source Code and Samples

Friday, 2 February 2007

Check for POP3 Messages


A great script from Paul Samways which allows you to check how many POP3 messages are in a mailbox.

Source Code

param ($Server, $Username, $Password);
$UsageScript = "Usage: getMail.msh [Server] [Username] [Password]";
$Port = 110;
if (($Server.length -lt 1) -or ($Username.length -lt 1) -or ($Password.length -lt 1)) {
write-output $UsageScript; break;
$TCPConnection = new-object -TypeName System.Net.Sockets.TcpClient($Server, $Port);
$NetStream = $TCPConnection.GetStream();
$Reader = new-object -TypeName System.IO.StreamReader($NetStream);
$Writer = new-object -TypeName System.IO.StreamWriter($NetStream);
$Buffer = $Reader.ReadLine();
$Writer.WriteLine("USER $Username");
$Writer.Flush(); $Buffer = $Reader.ReadLine();
$Writer.WriteLine("PASS $Password");
if ($Reader.ReadLine() -match "OK")
$writer.WriteLine("STAT"); $writer.Flush();
$NumOfMessage = $Reader.ReadLine().SubString(4, 1);
write-output "You Have $NumOfMessage Item(s) on $Server";
write-output "Authentication Error";

No comments: