I'm not a PowerShell expert.
Regular .NET code to connect to Gmail via IMAP looks like this:
using (Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("user@gmail.com", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen);
foreach (long uid in uids)
{
var eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);
string subject = email.Subject;
}
imap.Close();
}
I think Powershell code should look more or less like this:
[Reflection.Assembly]::LoadFile("c:\Mail.dll")
$imap = new-object Limilabs.Client.IMAP.Imap
$imap.ConnectSSL("imap.gmail.com")
$imap.UseBestLogin("user@gmail.com", "password")
$imap.SelectInbox();
$Expression = [Limilabs.Client.IMAP.Expression]
$uids = $imap.Search($Flag::Unseen)
foreach ($uid in $uids ) { $imap.GetMessageByUID($uid) }