Pures the deleted emails in current selected folder on IMAP4 server.
[Visual Basic 6.0] Public Sub Expunge( _ )
[Visual C++] public: HRESULT Expunge( );
Remarks
Example
[Visual Basic 6.0, VBScript, Visual C++] The following example demonstrates how to delete and pure email with EAGetMail POP3 & IMAP ActiveX Object. To get the full samples of EAGetMail, please refer to Samples section.
[Visual Basic 6.0]
Public Sub PureMail( _
ByVal sServer As String, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal bSSLConnection As Boolean)
Const MailServerPop3 = 0
Const MailServerImap4 = 1
'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"
'To receive email from imap4 server, please change
'MailServerPop3 to MailServerImap4 in MailServer constructor
Dim oServer As New EAGetMailObjLib.MailServer
oServer.Server = sServer
oServer.User = sUserName
oServer.Password = sPassword
oServer.SSLConnection = bSSLConnection
oServer.Protocol = MailServerImap4
If oServer.SSLConnection Then
oServer.Port = 993 'SSL IMAP4
Else
oServer.Port = 143 'IMAP4 normal
End If
On Error GoTo ErrorHandle
oClient.Connect oServer
Dim infos
infos = oClient.GetMailInfos()
Dim i, Count
Count = UBound(infos)
For i = LBound(infos) To Count
oClient.Delete (infos(i))
Next
'' Delete method just mark the email as deleted,
' Expunge method pure the emails from server exactly.
oClient.Expunge
oClient.Logout
Exit Sub
ErrorHandle:
''Error handle
MsgBox Err.Description
oClient.Close
End Sub
[VBScript]
Sub PureMail( _
ByVal sServer, _
ByVal sUserName, _
ByVal sPassword, _
ByVal bSSLConnection)
Const MailServerPop3 = 0
Const MailServerImap4 = 1
'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"
'To receive email from imap4 server, please change
'MailServerPop3 to MailServerImap4 in MailServer constructor
Dim oServer
Set oServer = CreateObject("EAGetMailObj.MailServer")
oServer.Server = sServer
oServer.User = sUserName
oServer.Password = sPassword
oServer.SSLConnection = bSSLConnection
oServer.Protocol = MailServerImap4
If oServer.SSLConnection Then
oServer.Port = 993 'SSL IMAP4
Else
oServer.Port = 143 'IMAP4 normal
End If
oClient.Connect oServer
Dim infos
infos = oClient.GetMailInfos()
Dim i, Count
Count = UBound(infos)
For i = LBound(infos) To Count
oClient.Delete (infos(i))
Next
'' Delete method just mark the email as deleted,
' Expunge method pure the emails from server exactly.
oClient.Expunge
oClient.Logout
End Sub
[Visual C++]
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
void PureMail(
LPCTSTR sServer,
LPCTSTR sUserName,
LPCTSTR sPassword,
bool bSSLConnection)
{
::CoInitialize( NULL );
const int MailServerPop3 = 0;
const int MailServerImap4 = 1;
try
{
IMailClientPtr oClient;
oClient.CreateInstance( "EAGetMailObj.MailClient" );
IMailServerPtr oServer;
oServer.CreateInstance( "EAGetMailObj.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( bSSLConnection )
{
oServer->Port = 995;
oServer->SSLConnection = VARIANT_TRUE;
}
else
{
oServer->Port = 110;
}
oClient->Connect( oServer );
_variant_t arInfo = oClient->GetMailInfos();
SAFEARRAY *psa = arInfo.parray;
long LBound = 0, UBound = 0;
SafeArrayGetLBound( psa, 1, &LBound );
SafeArrayGetUBound( psa, 1, &UBound );
INT count = UBound-LBound+1;
for( long i = LBound; i <= UBound; i++)
{
_variant_t vtInfo;
SafeArrayGetElement( psa, &i, &vtInfo );
IMailInfoPtr pInfo;
vtInfo.pdispVal->QueryInterface(__uuidof(IMailInfo), (void**)&pInfo);
//delete email from server
oClient->Delete( pInfo );
}
// Delete method just mark the email as deleted,
// Expunge method pure the emails from server exactly.
oClient->Expunge();
oClient->Logout();
}
catch( _com_error &ep )
{
_tprintf( _T("ERROR: %s\r\n"), (TCHAR*)ep.Description());
}
::CoUninitialize();
}