0

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()
Maylife
  • 37
  • 6
  • To me it looks more like an internal method used to make the dll work rather than a method that should be used to work with the dll. I could not find any docu either just the code on github where it's used to implement other methods like `Folder.Remove()` or `Folder.Rename()`. If you ever try to use MailKit / MimeKit you will know that ImapX is a lot easier and on a completely different complexity level. Unfortunaly it stopped working in my Scripts after a Windows Update some years ago and I had to move to MailKit... – T-Me May 17 '21 at 08:07
  • Do you need to download all messages on a regular basis? How about speeding up the script by fetching just unread mails or filtering them otherwise? – T-Me May 17 '21 at 08:09
  • I'll look into MimeKit, Ill see if it suits my needs. I still would like to get `SendAndReceive()` working. – Maylife May 18 '21 at 01:44
  • MimeKit and MailKit are lower-level libraries which tend to be more complex but also tend to be more powerful. That said, I try to strike a balance between providing lower-level access to IMAP, POP3, etc and making the API easy to use. Most of the other IMAP libraries went the other way and tried to make their IMAP clients mirror the simplicity of POP3 - e.g. "DownloadAllMessages()" which realistically doesn't make much sense if you have any IMAP folders that have 10,000+ messages like mine do :p – jstedfast May 19 '21 at 19:08

0 Answers0