+1 vote

Good morning,

downloaded imap component, but I can not connect to my GMAIL account via Powershell. Can you help me?

As I do for example to connect to the IMAP GMAIL box with the test user and password fictitious "test123"?

by

1 Answer

0 votes

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) }
by (301k points)
...