56257

Translating C# to PowerShell in InterIMAP

I'm having a problem with using C# in my PowerShell script. The library I'm trying to use is InterIMAP

Specifically, I am trying to convert this constructor:

using InterIMAP; IMAPConfig config = new IMAPConfig("server","username","password", true, false, "INBOX");

The PowerShell script I have so far:

$loadLib =[Reflection.Assembly]::LoadFile('C:\Users\......\InterIMAP.dll); $config= [InterIMAP.IMAP.IMAPConfig]::IMAPConfig("imap.gmail.com", $user, $password, $true, $true, "INBOX");

I think the issue I'm having is because the IMAP class has a pointer to the IMAPConfig class: http://interimap.codeplex.com/SourceControl/latest#InterIMAP/InterIMAP/Client/IMAP.cs

I must be doing something wrong. Any help appreciated

Answer1:

In your PowerShell code, you're accessing IMAPConfig() as a static method of the IMAPConfig class, which I'm guessing is not valid. In order to use an object constructor in PowerShell, you need to use the New-Object cmdlet.

The -TypeName parameter specifies the .NET class that you want to instantiate. The -ArgumentList parameter accepts an array of arbitrary System.Object objects that represent the constructor parameters.

$config = New-Object -TypeName InterIMAP.IMAP.IMAPConfig -ArgumentList @('imap.gmail.com', $User, $Password, $true, $true, 'INBOX');

Recommend

  • POP3 Library for .NET
  • IMAP GMAIL getting folder list problem
  • Can you use conditionals in IMAP_SEARCH from the PHP IMAP library?
  • How to get the number of unread gmail mails [closed]
  • How to display sharp icons in wxWIdgets
  • Getting Error like imap_open(): Couldn't open stream in server
  • How to call C# method in DLL from Runbook in Azure Automation?
  • Custom accordion content divs all share same size, no idea why
  • Loading files into variables in python
  • Cannot create StorageItem in Outlook Add-In
  • MVC - Dynamically loading Partial Views
  • How to develop MS CRM kind of application
  • Why can't I use non-integral types with switch [duplicate]
  • Deploying a CodeRush plugin from the Community Site
  • Available space left on drive - WinAPI - Windows CE
  • Detecting null parameter in preprocessor macro
  • Object and struct member access and address offset calculation
  • How to assign byte[] as a pointer in C#
  • x64 applications using gdi+: what are the consequences on performance?
  • Very simple C++ DLL that can be called from .net
  • ilmerge with a PFX file
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Optimizing database types to compact database (SQLite)
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • How do I fake an specific browser client when using Java's Net library?
  • Cassandra Data Model
  • Hazelcast - OperationTimeoutException
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • QuartzCore.framework for Mono Develop
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • C# - Getting references of reference
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can i traverse a binary tree from right to left in java?