Deleting emails via POP3/IMAP in Powershell

474 views Asked by At

My question here is how exactly do I go about deleting emails by id in gmail utilizing POP3 or IMAP without utilizing Netcmdlets or another external dependency. If it helps, I have some C# code which does a variety of mailbox functions, but I have no idea how to translate it into Powershell because I have never worked with C# before. https://github.com/andyedinborough/aenetmail/blob/master/Pop3Client.cs

1

There are 1 answers

1
AtomicFireball On BEST ANSWER

It's not a full port to PowerShell, but you should be able to use the Add-Type cmdlet to add the C# source code, and call the methods within PowerShell.

Copy the source code into a $Source variable.

Add the referenced assemblies to an $Assemblies variable

Use Add-Type -TypeDefinition $Source -Language CSharp -ReferencedAssemblies $Assemblies

Execute the methods with [AE.Net.Mail.Pop3Client]::MethodName()

Here's a good reading about using C# code in PowerShell on Technet