MailClient.AppendEx Method


Appends an email to specified IMAP4 folder with specified flags and datetime.

[Visual Basic 6.0]
Public Sub AppendEx( _
    oFolder As Imap4Folder, _
    data As Variant, _
    Flags As String, _
    MailDateTime As Date _
)
[Visual C++]
public: HRESULT AppendEx(
    IImap4Folder* oFolder,
    VARIANT data,
    BSTR Flags,
    DATE MailDateTime
);

Parameters

oFolder
The dest IMAP folder.
data
The binary data of email.
Flags
The flags of email, the value can be \Seen, \Deleted or (\Seen \Deleted)
MailDateTime
The datetime assigned to the email.

Example

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

[Visual Basic 6.0]
Public Sub AppendEmail(emlFile As String, _
Server As String, _
User As String, _
Password As String, _
SSLConnection As Boolean)

Const MailServerPop3 = 0
Const MailServerImap4 = 1

On Error GoTo ErrorHandle
    Dim oMail As New EAGetMailObjLib.Mail
    oMail.LicenseCode = "TryIt"
    oMail.LoadFile emlFile, False

    Dim oServer As New EAGetMailObjLib.MailServer
    oServer.Server = Server
    oServer.User = User
    oServer.Password = Password
    oServer.SSLConnection = SSLConnection
    oServer.Protocol = MailServerImap4
    If oServer.SSLConnection = True Then
        oServer.Port = 993
    Else
        oServer.Port = 143
    End If
    
    Dim oClient As New EAGetMailObjLib.MailClient
    oClient.LicenseCode = "TryIt"
    oClient.Connect oServer

    Dim arFolder
    arFolder = oClient.Imap4Folders
    Dim i
    For i = LBound(arFolder) To UBound(arFolder)
        Dim oFolder As EAGetMailObjLib.Imap4Folder
        Set oFolder = arFolder(i)
        If StrComp(oFolder.Name, "INBOX", vbTextCompare) = 0 Then
            'appends this email to "INBOX" folder
            oClient.AppendEx oFolder, oMail.Content, "\Seen \Deleted", Now()
            Exit For
        End If
    Next
    
    oClient.Logout
    Exit Sub
ErrorHandle:
    MsgBox Err.Description
    
End Sub

[VBScript]
Public Sub AppendEmail(emlFile, _
Server, _
User, _
Password, _
SSLConnection )

    Const MailServerPop3 = 0
    Const MailServerImap4 = 1

    Dim oMail
    Set oMail = CreateObject("EAGetMailObj.Mail")
    oMail.LicenseCode = "TryIt"
    oMail.LoadFile emlFile, False

    Dim oServer
    Set oServer = CreateObject("EAGetMailObj.MailServer")
    oServer.Server = Server
    oServer.User = User
    oServer.Password = Password
    oServer.SSLConnection = SSLConnection
    oServer.Protocol = MailServerImap4
    If oServer.SSLConnection = True Then
        oServer.Port = 993
    Else
        oServer.Port = 143
    End If
    
    Dim oClient
    Set oClient = CreateObject("EAGetMailObj.MailClient")
    oClient.LicenseCode = "TryIt"
    oClient.Connect oServer

    Dim arFolder
    arFolder = oClient.Imap4Folders
    Dim i
    For i = LBound(arFolder) To UBound(arFolder)
        Dim oFolder
        Set oFolder = arFolder(i)
        If StrComp(oFolder.Name, "INBOX", 1) = 0 Then
            'appends this email to "INBOX" folder
            oClient.AppendEx oFolder, oMail.Content, "\Seen \Deleted", Now()
            Exit For
        End If
    Next
    
    oClient.Logout    
End Sub

[Visual C++]
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;

void AppendMail( LPCTSTR lpszEmlFile,
    LPCTSTR lpszServer,
    LPCTSTR lpszUser,
    LPCTSTR lpszPassword,
    VARIANT_BOOL SSLConnection )
{

    ::CoInitialize( NULL );

    const int MailServerPop3 = 0;
    const int MailServerImap4 = 1;

    try
    {
        IMailPtr oMail = NULL;
        oMail.CreateInstance( "EAGetMailObj.Mail");
        oMail->LoadFile( lpszEmlFile, VARIANT_FALSE );

        IMailServerPtr oServer = NULL;
        oServer.CreateInstance("EAGetMailObj.MailServer");
        
        oServer->Server = lpszServer;
        oServer->User = lpszUser;
        oServer->Password = lpszPassword;
        oServer->SSLConnection = SSLConnection;
        oServer->Protocol = MailServerImap4;

        if( SSLConnection == VARIANT_TRUE )
            oServer->Port = 993;
        else
            oServer->Port = 143;

        IMailClientPtr oClient = NULL;
        oClient.CreateInstance("EAGetMailObj.MailClient");
        oClient->LicenseCode = _T("TryIt");
        oClient->Connect( oServer );

        _variant_t vtFolders = oClient->Imap4Folders;
        SAFEARRAY *psa = vtFolders.parray;
        LONG UBound = 0, LBound = 0;
    
        SafeArrayGetLBound( psa, 1, &LBound );
        SafeArrayGetUBound( psa, 1, &UBound );
        for( long i = LBound; i <= UBound; i++ )
        {
            _variant_t vt;
            SafeArrayGetElement( psa, &i, &vt );
            IImap4FolderPtr oFolder;
            vt.pdispVal->QueryInterface( __uuidof(IImap4Folder), (void**)&oFolder );
            if( _tcsicmp((TCHAR*)oFolder->Name, _T("INBOX")) == 0 )
            {
                //appends this email to "INBOX" folder
                SYSTEMTIME Timestamp;
                GetLocalTime(&Timestamp);
                DATE vTime;
                ::SystemTimeToVariantTime( &Timestamp, &vTime );
                oClient->AppendEx( oFolder, oMail->Content, _T("\\Seen \\Deleted"), vTime );
                break;
            }
        }
        oClient->Logout();
    }
    catch( _com_error &ep )
    {
        _tprintf( _T("%s\r\n"), (TCHAR*)ep.Description());
    }
    ::CoUninitialize();
}