MailClient.Undelete Method


Undelete the email marked as deleted on IMAP4server. POP3/Exchange Web Service/WebDAV protocol doesn't support this method.

[Visual Basic 6.0]
Public Sub Undelete( _
    info As MailInfo _
)
[Visual C++]
public: HRESULT Undelete(
    IMailInfo* info
);

Parameters

info
The email to undelete.

Example

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

[Visual Basic 6.0]
Public Sub ReceiveMail( _
ByVal sServer As String, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal bSSLConnection As Boolean)
    
    Const MailServerPop3 = 0
    Const MailServerImap4 = 1
    Const MailServerEWS = 2
    Const MailServerDAV = 3
    Const MailServerMsGraph = 4

    'For evaluation usage, please use "TryIt" as the license code, otherwise the
    '"invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then
    '"trial version expired" exception will be thrown.
    Dim oClient As New EAGetMailObjLib.MailClient
    oClient.LicenseCode = "TryIt"

    Dim oServer As New EAGetMailObjLib.MailServer
    oServer.Server = sServer
    oServer.User = sUserName
    oServer.Password = sPassword
    oServer.SSLConnection = bSSLConnection
    oServer.Protocol = MailServerImap4
    
    ''by default, the pop3 port is 110, imap4 port is 143,
    'the pop3 ssl port is 995, imap4 ssl port is 993
    'you can also change the port like this
    'oServer.Port = 110
    If oServer.Protocol = MailServerImap4 Then
        If oServer.SSLConnection Then
            oServer.Port = 993 'SSL IMAP4
        Else
            oServer.Port = 143 'IMAP4 normal
        End If
    Else
        If oServer.SSLConnection Then
            oServer.Port = 995 'SSL POP3
        Else
            oServer.Port = 110 'POP3 normal
        End If
    End If
    
On Error GoTo ErrorHandle
    oClient.Connect oServer
    
    Dim infos As EAGetMailObjLib.MailInfoCollection
    Set infos = oClient.GetMailInfoList()
    
    Dim i
    For i = 0 To infos.Count - 1
        Dim info As EAGetMailObjLib.MailInfo
        Set info = infos.Item(i)
        
        MsgBox "UIDL: " & info.UIDL
        MsgBox "Index: " & info.Index
        MsgBox "Size: " & info.Size
        'For POP3/Exchange Web Service/WebDAV, the IMAP4MailFlags is meaningless.
        MsgBox "Flags: " & info.IMAP4Flags 
        'For POP3, the Read is meaningless.
        MsgBox "Read: " & info.Read
        MsgBox "Deleted: " & info.Deleted

        ' undelete email         
        If info.Deleted Then
            oClient.Undelete info
        End If 
    Next

    oClient.Logout
    Exit Sub
ErrorHandle:
        ''Error handle
        MsgBox Err.Description
        
        oClient.Close
End Sub


[VBScript] Sub ReceiveMail( _ ByVal sServer, _ ByVal sUserName, _ ByVal sPassword, _ ByVal bSSLConnection) Const MailServerPop3 = 0 Const MailServerImap4 = 1 Const MailServerEWS = 2 Const MailServerDAV = 3 Const MailServerMsGraph = 4 'For evaluation usage, please use "TryIt" as the license code, otherwise the '"invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then '"trial version expired" exception will be thrown. Dim oClient Set oClient = CreateObject("EAGetMailObj.MailClient") oClient.LicenseCode = "TryIt" Dim oServer Set oServer = CreateObject("EAGetMailObj.MailServer") oServer.Server = sServer oServer.User = sUserName oServer.Password = sPassword oServer.SSLConnection = bSSLConnection oServer.Protocol = MailServerImap4 ''by default, the pop3 port is 110, imap4 port is 143, 'the pop3 ssl port is 995, imap4 ssl port is 993 'you can also change the port like this 'oServer.Port = 110 If oServer.Protocol = MailServerImap4 Then If oServer.SSLConnection Then oServer.Port = 993 'SSL IMAP4 Else oServer.Port = 143 'IMAP4 normal End If Else If oServer.SSLConnection Then oServer.Port = 995 'SSL POP3 Else oServer.Port = 110 'POP3 normal End If End If oClient.Connect oServer Dim infos Set infos = oClient.GetMailInfoList() Dim i For i = 0 To infos.Count - 1 Dim info Set info = infos.Item(i) MsgBox "UIDL: " & info.UIDL MsgBox "Index: " & info.Index MsgBox "Size: " & info.Size 'For POP3/Exchange Web Service/WebDAV, the IMAP4MailFlags is meaningless. MsgBox "Flags: " & info.IMAP4Flags 'For POP3, the Read is meaningless. MsgBox "Read: " & info.Read MsgBox "Deleted: " & info.Deleted ' undelete email If info.Deleted Then oClient.Undelete info End If Next oClient.Logout End Sub
[Visual C++] #include "stdafx.h" #include <windows.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void ReceiveMail( LPCTSTR sServer, LPCTSTR sUserName, LPCTSTR sPassword, bool bSSLConnection) { ::CoInitialize(NULL); const int MailServerPop3 = 0; const int MailServerImap4 = 1; const int MailServerEWS = 2; const int MailServerDAV = 3; const int MailServerMsGraph = 4; try { IMailClientPtr oClient; oClient.CreateInstance(__uuidof(EAGetMailObjLib::MailClient)); IMailServerPtr oServer; oServer.CreateInstance(__uuidof(EAGetMailObjLib::MailServer)); // For evaluation usage, please use "TryIt" as the license code, otherwise the // "invalid license code" exception will be thrown. However, the object will expire in 1-2 months, then // "trial version expired" exception will be thrown. oClient->LicenseCode = _T("TryIt"); oServer->Server = sServer; oServer->User = sUserName; oServer->Password = sPassword; INT nProtocol = MailServerImap4; oServer->Protocol = nProtocol; if(nProtocol == MailServerPop3) { if(bSSLConnection) { oServer->Port = 995; oServer->SSLConnection = VARIANT_TRUE; } else { oServer->Port = 110; } } else { if(bSSLConnection) { oServer->Port = 993; oServer->SSLConnection = VARIANT_TRUE; } else { oServer->Port = 143; } } oClient->Connect(oServer); IMailInfoCollectionPtr infos = oClient->GetMailInfoList(); for(long i = 0; i < infos->Count; i++) { IMailInfoPtr pInfo = infos->GetItem(i); _tprintf(_T("UIDL: %s\r\n"), (TCHAR*)pInfo->UIDL); _tprintf(_T("Index: %d\r\n"), pInfo->Index); _tprintf(_T("Size: %d\r\n"), pInfo->Size); //For POP3/Exchange Web Service/WebDAV, the IMAP4MailFlags is meaningless _tprintf(_T("Flags: %s\r\n"), (TCHAR*)pInfo->IMAP4Flags); //For POP3, the Read is meaningless _tprintf(_T("Read: %s\r\n"), (pInfo->Read == VARIANT_TRUE)?_T("TRUE"):_T("FALSE")); _tprintf(_T("Deleted: %s\r\n"), (pInfo->Deleted == VARIANT_TRUE)?_T("TRUE"):_T("FALSE")); // mark read email as unread if( pInfo->Deleted == VARIANT_TRUE) { oClient->Undelete(pInfo); } } oClient->Logout(); } catch(_com_error &ep) { _tprintf(_T("ERROR: %s\r\n"), (TCHAR*)ep.Description()); } ::CoUninitialize(); }

See Also

MailClient.Delete Method
MailClient.Reset Method