Creates a mail folder on IMAP4/MS Exchange server.
[Visual Basic 6.0]
Public Function CreateFolder( _
root As Imap4Folder, _
folderName As String _
) As Imap4Folder
[Visual C++]
public: HRESULT CreateFolder(
IImap4Folder* root,
BSTR folderName,
IImap4Folder** pVal
);
Parameters
Return Value
Example
[Visual Basic 6.0, VBScript, Visual C++, Delphi] The following example demonstrates how to create, subscribe, unsubscribe and delete "TestFolder" with EAGetMail POP3 & IMAP ActiveX Object. To get the full samples of EAGetMail, please refer to Samples section.
[Visual Basic 6.0]
Public Sub CreateFolder(ByVal Server As String, _
ByVal User As String, _
ByVal Password As String, _
ByVal SSLConnection As Boolean)
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Const MailServerEWS = 2
Const MailServerDAV = 3
Const MailServerMsGraph = 4
On Error GoTo ErrorHandle
Dim oServer As New EAGetMailObjLib.MailServer
oServer.Server = Server
oServer.User = User
oServer.Password = Password
oServer.SSLConnection = SSLConnection
oServer.Protocol = MailServerImap4
'To create folder with Exchange Web Service, please change
'MailServerImap4 to MailServerEWS to MailServer.Protocol
'To create folder 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.
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 EAGetMailObjLib.Imap4Folder
Set oFolder = oClient.CreateFolder(Nothing, "Test Folder")
'Only IMAP4 protocol supports Subscribe/Unsubscribe
If oServer.Protocol = MailServerImap4 Then
If Not oFolder.Subscribed Then
oClient.SubscribeFolder oFolder
End If
End If
Dim folders
Set folders = oClient.GetFolderList()
Dim i
For i = 0 To folders.Count - 1
Dim fd As EAGetMailObjLib.Imap4Folder
Set fd = folders.Item(i)
MsgBox "folder: " & fd.FullPath
Next
'Only IMAP4 protocol supports Subscribe/Unsubscribe
If oServer.Protocol = MailServerImap4 Then
oClient.UnsubscribeFolder oFolder
End If
oClient.DeleteFolder oFolder
oClient.Logout
Exit Sub
ErrorHandle:
MsgBox Err.Description
End Sub
[VBScript]
Sub CreateFolder(ByVal Server, _
ByVal User, _
ByVal Password, _
ByVal SSLConnection )
Const MailServerPop3 = 0
Const MailServerImap4 = 1
Const MailServerEWS = 2
Const MailServerDAV = 3
Const MailServerMsGraph = 4
Dim oServer
Set oServer = CreateObject("EAGetMailObj.MailServer")
oServer.Server = Server
oServer.User = User
oServer.Password = Password
oServer.SSLConnection = SSLConnection
oServer.Protocol = MailServerImap4
'To create folder with Exchange Web Service, please change
'MailServerImap4 to MailServerEWS to MailServer.Protocol
'To create folder 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.
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
Set oFolder = oClient.CreateFolder(Nothing, "Test Folder")
'Only IMAP4 protocol supports Subscribe/Unsubscribe
If oServer.Protocol = MailServerImap4 Then
If Not oFolder.Subscribed Then
oClient.SubscribeFolder oFolder
End If
End If
Dim folders
Set folders = oClient.GetFolderList()
Dim i
For i = 0 To folders.Count - 1
Dim fd
Set fd = folders.Item(i)
MsgBox "folder: " & fd.FullPath
Next
'Only IMAP4 protocol supports Subscribe/Unsubscribe
If oServer.Protocol = MailServerImap4 Then
oClient.UnsubscribeFolder oFolder
End If
oClient.DeleteFolder oFolder
oClient.Logout
End Sub
[Visual C++]
#include "stdafx.h"
#include <windows.h>
#include "eagetmailobj.tlh"
using namespace EAGetMailObjLib;
void CreateFolder(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
{
IMailServerPtr oServer = NULL;
oServer.CreateInstance(__uuidof(EAGetMailObjLib::MailServer));
oServer->Server = lpszServer;
oServer->User = lpszUser;
oServer->Password = lpszPassword;
oServer->SSLConnection = SSLConnection;
oServer->Protocol = MailServerImap4;
//To create folder with Exchange Web Service, please change
//MailServerImap4 to MailServerEWS to MailServer.Protocol
//To create folder 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
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);
IImap4FolderPtr oFolder = oClient->CreateFolder(NULL, _T("Test Folder"));
//Only IMAP4 protocol supports Subscribe/Unsubscribe
if(oServer->Protocol == MailServerImap4)
{
if(oFolder->Subscribed == VARIANT_FALSE)
{
oClient->SubscribeFolder(oFolder);
}
}
IFolderCollectionPtr folders = oClient->GetFolderList();
for(long i = 0; i < folders->Count; i++ )
{
IImap4FolderPtr fd = folders->GetItem(i);
_tprintf(_T("folder: %s\r\n"), (TCHAR*)fd->FullPath);
}
//Only IMAP4 protocol supports Subscribe/Unsubscribe
if(oServer->Protocol == MailServerImap4)
{
oClient->UnsubscribeFolder(oFolder);
}
oClient->DeleteFolder(oFolder);
oClient->Logout();
}
catch(_com_error &ep)
{
_tprintf(_T("%s\r\n"), (TCHAR*)ep.Description());
}
::CoUninitialize();
}
[Delphi]
const
MailServerPop3 = 0;
MailServerImap4 = 1;
MailServerEWS = 2;
MailServerDAV = 3;
procedure CreateFolder(server: WideString; user: WideString; password: WideString; useSslConnection: Boolean);
var
oClient: TMailClient;
oServer: TMailServer;
folders: IFolderCollection;
i: integer;
fd, folder: IImap4Folder;
begin
try
// To create folder with Exchange Web Service, please change
// MailServerImap4 to MailServerEWS to MailServer.Protocol
// To create folder 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 := TMailServer.Create(Application);
oServer := TMailServer.Create(Application);
oServer.Server := server;
oServer.User := user;
oServer.Password := password;
oServer.Protocol := MailServerImap4;
// Enable SSL/TLS Connection, most modern email server require SSL/TLS connection by default.
oServer.SSLConnection := useSslConnection;
if useSslConnection then
begin
// Set 993 SSL IMAP port
oServer.Port := 993;
end
else
begin
// Set 143 IMAP port
oServer.Port := 143;
end;
oClient := TMailClient.Create(Application);
oClient.LicenseCode := 'TryIt';
oClient.Connect1(oServer.DefaultInterface);
ShowMessage('Connected!');
folder := oClient.CreateFolder(nil, 'Test Folder');
folders := oClient.GetFolderList();
for i := 0 to folders.Count - 1 do
begin
fd := folders.Item[i];
ShowMessage('Folder: ' + fd.FullPath);
end;
oClient.DeleteFolder(folder);
oClient.Logout;
except
on ep:Exception do
ShowMessage('Error: ' + ep.Message);
end;
end;
end.
See Also
MailClient.RenameFolder
MailClient.DeleteFolder
MailClient.SubscribeFolder
MailClient.UnsubscribeFolder