MailClient.Expunge Method


expunges the deleted emails in current selected folder on IMAP4 server.

[Visual Basic]
Public Sub Expunge( _
)

Public Async Function ExpungeAsync( _
)As Task
[C#]
public void Expunge(
);

public async Task ExpungeAsync(
);
[C++]
public: void Expunge(
);
[JScript]
public function Expunge(
);

Remarks

MailClient.Delete method only marks the email as deleted, only the MailClient.Quit method (POP3 and IMAP4) or MailClient.Expunge method(IMAP4 only) expunges the deleted email from server. For POP3, deleted flag will lose if the connection is closed; FOR IMAP4, the deleted flag is permant even the connection is closed.

Example

[Visual Basic, C#, C++] The following example demonstrates how to delete and expunge email with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.

[VB - Expunge emails]
Imports System
Imports System.Globalization
Imports System.IO
Imports System.Text
Imports EAGetMail

Public Class TestClass
    Public Sub ExpungeMail(server As String, user As String, password As String, useSsl As Boolean)

        Try
            ' Most modern email server require SSL/TLS connection, 
            ' set useSsl to true Is recommended.
            Dim oServer As New MailServer(server, user, password, useSsl,
                        ServerAuthType.AuthLogin, ServerProtocol.Imap4)

            ' IMAP4 port Is 143,  IMAP4 SSL port Is 993.
            oServer.Port = If(useSsl, 993, 143)

            Console.WriteLine("Connecting server ...")
            Dim oClient As New MailClient("TryIt")
            oClient.Connect(oServer)

            Console.WriteLine("Retrieving email list ...")
            Dim infos() As MailInfo = oClient.GetMailInfos()

            Console.WriteLine("Total {0} email(s)", infos.Length)

            For i As Integer = 0 To infos.Length - 1
                Dim info As MailInfo = infos(i)

                ' Mark email as deleted on server.
                Console.WriteLine("Deleting ... {0}/{1}", i + 1, infos.Length)
                oClient.Delete(info)
            Next

            Console.WriteLine("Disconnecting ...")
            ' Delete method just mark the email as deleted, 
            ' Expunge method expunge the emails from server permanently.
            oClient.Expunge()

            oClient.Logout()
            Console.WriteLine("Completed!")
        Catch ep As Exception
            Console.WriteLine("Error: {0}", ep.Message)
        End Try

    End Sub
End Class


[C# - Expunge emails] using System; using System.IO; using System.Globalization; using System.Text; using EAGetMail; class TestClass { public void ExpungeMail(string server, string user, string password, bool useSsl) { try { // Most modern email server require SSL/TLS connection, // set useSsl to true is recommended. MailServer oServer = new MailServer(server, user, password, useSsl, ServerAuthType.AuthLogin, ServerProtocol.Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. oServer.Port = (useSsl) ? 993 : 143; Console.WriteLine("Connecting server ..."); MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); Console.WriteLine("Retreiving email list ..."); MailInfo[] infos = oClient.GetMailInfos(); Console.WriteLine("Total {0} email(s)", infos.Length); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; // Mark the email as deleted on server. Console.WriteLine("Deleting ... {0}/{1}", i + 1, infos.Length); oClient.Delete(info); } Console.WriteLine("Disconnecting ..."); // Delete method just mark the email as deleted, // Expunge method expunge the emails from server permanently. oClient.Expunge(); oClient.Logout(); Console.WriteLine("Completed!"); } catch (Exception ep) { Console.WriteLine("Error: {0}", ep.Message); } } }
[C++/CLI - Expunge emails] using namespace System; using namespace System::Globalization; using namespace System::IO; using namespace EAGetMail; //add EAGetMail namespace void ExpungeMail(String ^server, String ^user, String ^password, bool useSsl) { try { // Most modern email server require SSL/TLS connection, // set useSsl to true is recommended. MailServer ^oServer = gcnew MailServer(server, user, password, useSsl, ServerAuthType::AuthLogin, ServerProtocol::Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. oServer->Port = (useSsl) ? 993 : 143; Console::WriteLine("Connecting server ..."); MailClient ^oClient = gcnew MailClient("TryIt"); oClient->Connect(oServer); Console::WriteLine("Retreiving email list ..."); array<MailInfo^>^infos = oClient->GetMailInfos(); Console::WriteLine("Total {0} email(s)", infos->Length); for (int i = 0; i < infos->Length; i++) { MailInfo ^info = infos[i]; // Mark email as deleted on server. Console::WriteLine("Deleting ... {0}/{1}", i + 1, infos->Length); oClient->Delete(info); } Console::WriteLine("Disconnecting ..."); // Delete method just mark the email as deleted, // Expunge method expunge the emails from server permanently. oClient->Expunge(); oClient->Logout(); Console::WriteLine("Completed!"); } catch (Exception ^ep) { Console::WriteLine("Error: {0}", ep->Message); } }

See Also

MailClient.Delete Method
MailClient.Reset Method