Issue a custom command to IMAP server

You can send any command to IMAP server using Mail.dll .NET IMAP component.

In this example we will issue a standard NOOP (NO OPeration) command. This command can be used as a periodic poll for new messages. Can also be used to reset any inactivity auto-logout timer on the IMAP server.

Of course there is a Noop() method on Imap class, but this example is about issuing any command yourself.

// C# version:

using System;
using Limilabs.Mail;
using Limilabs.Client.IMAP;

class Program
{
    static void Main(string[] args)
    {
       using (Imap imap = new Imap())
       {
           imap.Connect("imap.example.com");
           imap.Login("user", "password");

           imap.SelectInbox();

           ImapResponse response = imap.SendCommand("NOOP");
           foreach (string line in response.Lines)
           {
               Console.WriteLine(line);
           }

           imap.Close();
       }
    }
};
' VB.NET version:

Imports System
Imports Limilabs.Mail
Imports Limilabs.Client.IMAP


Using imap As New Imap()
	imap.Connect("imap.example.com")
	imap.Login("user", "password")

	imap.SelectInbox()

	Dim response As ImapResponse = imap.SendCommand("NOOP")
	For Each line As String In response.Lines
		Console.WriteLine(line)
	Next

	imap.Close()
End Using

Tags: , , ,

Questions?

Consider using our Q&A forum for asking any questions.