Appends an email to specified IMAP4/MS Exchange mail 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
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]
Function FindFolder(ByVal FolderPath As String, ByRef folders As FolderCollection)
Dim i As Long
For i = 0 To folders.Count - 1
Dim oFolder As Imap4Folder
Set oFolder = folders.Item(i)
If StrComp(oFolder.LocalPath, FolderPath, 1) = 0 Then
Set FindFolder = oFolder
Exit Function
End If
Set oFolder = FindFolder(FolderPath, oFolder.SubFolderList)
If Not (oFolder Is Nothing) Then
Set FindFolder = oFolder
Exit Function
End If
Next
Set FindFolder = Nothing
End Function
Public Sub AppendEmail(emlFile As String, _
Server As String, _
User As String, _
Password As String, _
SSLConnection As Boolean)
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Const MailServerEWS = 2
Const MailServerDAV = 3
Const MailServerMsGraph = 4
On Error GoTo ErrorHandle
Dim oMail As New EAGetMailObjLib.Mail
oMail.LicenseCode = "TryIt"
oMail.LoadFile emlFile, False
'To append/upload email with Exchange Web Service, please change
'MailServerImap4 to MailServerEWS to MailServer.Protocol
'To append/upload email with Exchange WebDAV, please change
'MailServerImap4 to MailServerDAV to MailServer.Protocol
'Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007
'or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4
'to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or
'later version) or WebDAV(Exchange 2000/2003) protocol.
'For Exchange Web Service/WebDAV, please ignore
'Port property. But for Exchange Web Service, please set SSLConnection to True
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 oFolder As Imap4Folder
'' If you want search sub folder, use parentfolder\subfolder
' For example: INBOX\MySubFolder
Set oFolder = FindFolder("INBOX", oClient.GetFolderList())
If oFolder Is Nothing Then
MsgBox "No folder found!"
Exit Sub
End If
'appends this email to "INBOX" folder
oClient.AppendEx oFolder, oMail.Content, "\Seen \Deleted", Now()
oClient.Logout
Exit Sub
ErrorHandle:
MsgBox Err.Description
End Sub
[VBScript]
Function FindFolder(ByVal FolderPath, ByRef folders)
Dim i
For i = 0 To folders.Count - 1
Dim oFolder
Set oFolder = folders.Item(i)
If StrComp(oFolder.LocalPath, FolderPath, 1) = 0 Then
Set FindFolder = oFolder
Exit Function
End If
Set oFolder = FindFolder(FolderPath, oFolder.SubFolderList)
If Not (oFolder Is Nothing) Then
Set FindFolder = oFolder
Exit Function
End If
Next
Set FindFolder = Nothing
End Function
Public Sub AppendEmail(emlFile, _
Server, _
User, _
Password, _
SSLConnection )
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Const MailServerEWS = 2
Const MailServerDAV = 3
Const MailServerMsGraph = 4
Dim oMail
Set oMail = CreateObject("EAGetMailObj.Mail")
oMail.LicenseCode = "TryIt"
oMail.LoadFile emlFile, False
'To append/upload email with Exchange Web Service, please change
'MailServerImap4 to MailServerEWS to MailServer.Protocol
'To append/upload email with Exchange WebDAV, please change
'MailServerImap4 to MailServerDAV to MailServer.Protocol
'Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007
'or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4
'to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or
'later version) or WebDAV(Exchange 2000/2003) protocol.
'For Exchange Web Service/WebDAV, please ignore
'Port property. But for Exchange Web Service, please set SSLConnection to True
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 oFolder
'' If you want search sub folder, use parentfolder\subfolder
' For example: INBOX\MySubFolder
Set oFolder = FindFolder("INBOX", oClient.GetFolderList())
If oFolder Is Nothing Then
MsgBox "No folder found!"
Exit Sub
End If
'appends this email to "INBOX" folder
oClient.AppendEx oFolder, oMail.Content, "\Seen \Deleted", Now()
oClient.Logout
End Sub
[Visual C++]
#include "stdafx.h"
#include <windows.h>
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
IImap4FolderPtr FindFolder(LPCTSTR folderPath, IFolderCollectionPtr& folders)
{
for(long i = 0; i < folders->Count; i++)
{
IImap4FolderPtr oFolder = folders->GetItem(i);
if(_tcsicmp((TCHAR*)oFolder->LocalPath, folderPath) == 0)
{
return oFolder;
}
IFolderCollectionPtr subFolders = oFolder->SubFolderList;
oFolder = FindFolder(folderPath, subFolders);
if(oFolder != NULL)
{
return oFolder;
}
}
return NULL;
}
void AppendMail(LPCTSTR lpszEmlFile,
LPCTSTR lpszServer,
LPCTSTR lpszUser,
LPCTSTR lpszPassword,
VARIANT_BOOL SSLConnection)
{
::CoInitialize(NULL);
const int MailServerPop3 = 0;
const int MailServerImap4 = 1;
const int MailServerEWS = 2;
const int MailServerDAV = 3;
const int MailServerMsGraph = 4;
try
{
IMailPtr oMail = NULL;
oMail.CreateInstance(__uuidof(EAGetMailObjLib::Mail));
oMail->LicenseCode = _T("TryIt");
oMail->LoadFile(lpszEmlFile, VARIANT_FALSE);
IMailServerPtr oServer = NULL;
oServer.CreateInstance(__uuidof(EAGetMailObjLib::MailServer));
//To append/upload email with Exchange Web Service, please change
//MailServerImap4 to MailServerEWS to MailServer.Protocol
//To append/upload email with Exchange WebDAV, please change
//MailServerImap4 to MailServerDAV to MailServer.Protocol
//Exchange Server supports POP3/IMAP4 protocol as well, but in Exchange 2007
//or later version, POP3/IMAP4 service is disabled by default. If you don't want to use POP3/IMAP4
//to download email from Exchange Server, you can use Exchange Web Service(Exchange 2007/2010 or
//later version) or WebDAV(Exchange 2000/2003) protocol.
//For Exchange Web Service/WebDAV, please ignore
//Port property. But for Exchange Web Service, please set SSLConnection to True
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(__uuidof(EAGetMailObjLib::MailClient));
oClient->LicenseCode = _T("TryIt");
oClient->Connect(oServer);
IFolderCollectionPtr folders = oClient->GetFolderList();
// If you want search sub folder, use parentfolder\subfolder
// For example: INBOX\\MySubFolder
IImap4FolderPtr oFolder = FindFolder(_T("INBOX"), folders);
if(oFolder != NULL)
{
//appends this email to "INBOX" folder
SYSTEMTIME Timestamp;
GetLocalTime(&Timestamp);
DATE vTime;
::SystemTimeToVariantTime( &Timestamp, &vTime );
oClient->AppendEx(oFolder, oMail->Content, _T("\\Seen \\Deleted"), vTime);
}
oClient->Logout();
}
catch(_com_error &ep)
{
_tprintf(_T("%s\r\n"), (TCHAR*)ep.Description());
}
::CoUninitialize();
}
See Also