Using SendAndReceive() with ImapX

309 Views Asked by At

I am trying to use the ImapX DLL effectively. I have got $client.Folders.Inbox.Search() and $client.Folders.Inbox.Messages.Download() to work for downloading messages but they're very slow. I was looking into using $client.SendAndReceive() instead. I thought it would work like Outlook's send and receive but it wants a lot of parameters I don't understand.

This is the method definition:
bool SendAndReceive(string command, [ref] System.Collections.Generic.IList[string] data, ImapX.Parsing.CommandProcessor processor, System.Text.Encoding encoding, bool pushResultToDatadespiteProcessor)

I don't know what any of the parameters are for. I searched online for documentation for ImapX, but I couldn't find anything helpful.

Is SendAndReceive() a good method for downloading messages? If so, how do I use it?

This is my PowerShell code so far:

$DLL = [Reflection.Assembly]::LoadFile(“$PSScriptRoot\DLL\ImapX.dll”)

$client = New-Object ImapX.ImapClient 


$client.IsDebug = $true
$client.ValidateServerCertificate = $true
$client.ThrowConnectExceptions = $true
$client.UseSsl = $false
$client.Behavior.MessageFetchMode = "Full"

$client.Host = $mailHost
$client.Port = $Port

$client.Connect()
$client.Login($user,$password)

# Downloads all messages but very slow
$client.Folders.Inbox.Search("ALL", $client.Behavior.MessageFetchMode)
$client.Folders.Inbox.Messages.Download()
0

There are 0 best solutions below