In previous section, I introduced how to parse non-delivery report (NDR) in VB 6.0. In this section, I will introduce how to create folders and manage folders with IMAP4/Exchange Web Service (EWS)/WebDAV protocol in VB 6.0.
Because IMAP4/Exchange Web Service (EWS)/WebDAV protocol supports folder access, so we can retrieve email from other mailbox rather than default “INBOX”, I have introduced it in other sections. In this section, I will introduce how to use EAGetMail to create folder and delete folder with IMAP4/Exchange Web Service/WebDAV protocol. Notice: POP3 protocol doesn’t support this feature.
The following example codes demonstrate how to create folder and delete folder.
To get the full sample projects, please refer to Samples section.
Option Explicit Const MailServerPop3 = 0 Const MailServerImap4 = 1 Const MailServerEWS = 2 Const MailServerDAV = 3 Private Sub Command1_Click() ' 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. Dim oServer As New EAGetMailObjLib.MailServer oServer.Server = "imap4.emailarchitect.net" oServer.User = "firstname.lastname@example.org" oServer.Password = "testpassword" oServer.Protocol = MailServerImap4 ' Enable SSL/TLS connection, most modern email servers require SSL/TLS by default oServer.SSLConnection = True oServer.Port = 993 ' If your IMAP doesn't deploy SSL connection ' Please use ' oServer.SSLConnection = False ' oServer.Port = 143 On Error GoTo ErrorHandle: Dim oClient As New EAGetMailObjLib.MailClient oClient.LicenseCode = "TryIt" oClient.Connect oServer MsgBox "Connected" Dim oFolder As EAGetMailObjLib.Imap4Folder Set oFolder = oClient.CreateFolder(Nothing, "Test Folder") 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 oClient.DeleteFolder oFolder oClient.Logout Exit Sub ErrorHandle: MsgBox Err.Description End Sub
To retrieve emails from a specified folder, please use SelectFolder method; To move email from a folder to another folder, please use Move method; To copy email from a folder to another folder, please use Copy method; To upload an email file from local disk to server folder, please use Append method.
Please refer to ImapFull project for more detail.
Since Exchange 2007 or later version (2010/203), IMAP4 protocol does not expose public folders to mail client. If you want to access public folders on MS Exchange 2007/2010/2013/2016/2019 or later version, please use MailClient.QueryEWSPublicFolders method.
Total sample projects in EAGetMail Mail Component installation package.
If you have any comments or questions about above example codes, please click here to add your comments.