Using Aspose.Email IMAP client in Powershell

Hi support.
I want to have a Powershell script access an IMAP mail server and do some automation.
Since I have an Aspose.Regarding the email license, I thought I would try using Aspose.Email Aspose.Email (23.11.0.0, .NETFrameworE v4.5).

The Powershell (7.3) code below throws the following error:
Error: Exception calling “ListMessages” with “1” argument(s): “The type initializer for ‘#=zCFP7hrvmVjPEO6to_WD035ORPOGDBp7EzQ==’ threw an exception.”

Research points to requiring loading (some or all) dll’s referenced by Aspose.Email (which is quite a few).

Can you help?

/Morten

$emailLicense = New-Object Aspose.Email.License
$emailLicense.SetLicense($path_License)

$imapClient = New-Object Aspose.Email.Clients.Imap.ImapClient($server_host, $account_username, $account_passowrd)
$imapClient.SecurityOptions = [Aspose.Email.Clients.SecurityOptions]::Auto

$imapQueryBuilder = New-Object Aspose.Email.Clients.Imap.ImapQueryBuilder
$imapQueryBuilder.HasNoFlags([Aspose.Email.Clients.Imap.ImapMessageFlags]::IsRead)
$query = $imapQueryBuilder.GetQuery()

$imapClient.SelectFolder(“Inbox”)

try {
$messageInfoCol = $imapClient.ListMessages($query)
"Initial Unread Count: " + $messageInfoCol.Count
} catch {
Write-Output “Error: $_”
}

Hello @mortenma,

There might be an incompatibility issue between the frameworks. Please try using the Aspose.Email version that is compatible with .NET Core.

Thanks, Margarita.
I didn’t think of this. My bad.
It worked with the Aspose.Email (23.12.0.0, .NETCoreApp, v6.0) dll

@mortenma ,

Feel free to write to us if you have any additional query/inquiry related to Aspose.Email. We’ll be glad to assist you further.