IMAP4 Object
You can use the IMAP4
object to establish the connection with the IMAP4 server, select and manage
the IMAP4 mailboxes, examine and alter properties of the messages, search for
messages that match a criteria, and download entire messages.
Another features of the IMAP4 object include secure authentication options (OAuth 2.0, NTLM, GSSAPI/Kerberos and others),
Integrated Windows Authentication with no username/password specified,
ability to execute user-supplied commands, upload messages to the server and
copy messages between mailboxes, and more.
Note: By default, the IMAP4 object neither processes Windows events
nor fires its own events. This ensures maximum performance in the server environment
such as ASP, but causes the user interface of desktop applications to be not
responsive. To enable event handling and firing, you can set EnableEvents
property value to True.
Syntax
IMAP4.property|method
Properties | |
AuthMethod | Specifies the authentication method to use when logging in the IMAP4 mail account. |
Busy | Indicates whether the IMAP4 object is in the progress of sending or receiving data. |
ClientRequest | Returns the last command string sent to the IMAP4 server. |
Connected | Indicates whether the IMAP4 session is active. |
EnableEvents | Specifies whether the IMAP4 object will handle and fire events. |
EnableLogging | Specifies whether the IMAP4 object must log the IMAP4 session into a file. |
ErrCode | Completion status of the last command. |
ErrDesc | Contains textual error description if the last command has completed with an error. |
IsError | Indicates whether the last command has completed with errors. |
Licensed | Indicates whether valid license key has been assigned to the IMAP4 object. |
LicenseKey | Sets the license key to be used with the IMAP4 object. |
LogFilePath | Sets filename of the IMAP4 session log file. |
MessageCount | The total number of messages in the currently selected mailbox. |
MessageSet | Specifies the sequence of ordinal message numbers or UIDs to be processed. |
Password | The password of the user account on the IMAP4 server. |
PortNumber | The port number of the IMAP4 service on the server. Defaults to 143. |
QuotaUsage | Gets the size of the occupied space in the mailbox in kilobytes. |
RecentCount | The number of recent messages in the currently selected mailbox. |
Selected | Indicates whether a mailbox has been selected. |
SendDelay | Gets or sets the delay in milliseconds between two successive requests to the IMAP server. |
ServerName | The IMAP4 server name. |
ServerResponse | Returns the string that contains the entire last reply from the IMAP4 server. |
ServerStatusResponse | The string containing completion status part of the last reply from the IMAP4 server. |
SmartParsing |
Enables better error recovery from bad-formatted responses from some IMAP servers. |
SSL | Provides access to the SSL settings. |
TargetName | The SPN of the server (only used with Kerberos authentication). |
Timeout | The timeout value in seconds. |
UIDNext | Returns UIDNEXT value of the currently selected IMAP4 mailbox. |
UIDPlusResult | Returns UIDPLUS result of the last IMAP4 command, such as APPEND, COPY, or MOVE. |
UIDValidity | Returns UIDVALIDITY value of the currently selected IMAP4 mailbox. |
Unseen | Gets the ordinal message number of the first unseen message in the currently selected mailbox. |
UserDomain | The name of the user domain on the IMAP4 server (only used with MS specific authentication types like NTLM). |
UserName | The name of the user account on the IMAP4 server. |
UTF7EncodeMailboxNames | Tells MailBee whether to automatically encode IMAP mailbox names to UTF-7M when sending requests to the server. |
Methods | |
Abort | Aborts current operation and immediately closes the IMAP4 session. |
AppendMessage | Uploads a message to the specified mailbox. |
ClearLog | Clears the IMAP4 session log file. |
Connect | Connects to the IMAP4 server and logs in the user mail account. |
CopyMessages | Copies specified messages from the currently selected mailbox to another mailbox. |
CreateMailbox | Creates a mailbox in the user account on the IMAP4 server. |
DeleteMailbox | Deletes specified mailbox from the user account. |
DeleteMessages | Marks the specified message in the currently selected mailbox as "Deleted". |
Disconnect | Disconnects from the IMAP4 server. |
ExamineMailbox | Selects specified mailbox on the IMAP4 server for read-only access. |
Expunge | Permanently removes all messages marked as "Deleted" from the currently selected mailbox. |
ExpungeAndClose | Permanently removes all messages marked as "Deleted" and closes currently selected mailbox. |
FromUTF7 | Decodes the specified UTF-7M string into regular string. |
GetCapabilities | Gets the the list of capabilities of this server or checks if the specified capability is supported by this server. |
GetLastReceivedDataChunk | Gets the data portion received from the server during last receive-data operation. |
GetMailboxQuota | Retrieves the quota size for the mailbox or the entire mail account in kilobytes. |
GetMailboxStatus | Retrieves some statistics for a mailbox (total and unseen message count, etc). |
Idle | Receives status notifications from the server in IDLE mode. |
MoveMessages | Moves specified messages from the currently selected mailbox to another mailbox (the server must support MOVE extension). |
Ping | Sends NOOP command to the IMAP4 server. |
RenameMailbox | Renames specified mailbox on the IMAP4 server. |
RetrieveEnvelopes | Retrieves one or more message envelopes from the currently selected mailbox. |
RetrieveEnvelopesEx | Retrieves message envelopes with extended information from the currently selected mailbox. |
RetrieveMailboxes | Retrieves a list of mailboxes available in the user account on the IMAP4 server. |
RetrieveMailboxesEx | Retrieves Mailboxes collection which contains those mailboxes of the IMAP4 account which meet the specified criteria. Supports XLIST, SPECIAL-USE, CHILDREN extensions and special folder flags like Sent or Drafts. |
RetrieveMessagesSize | Retrieves total size in bytes of one or more messages in the currently selected mailbox. |
RetrieveSingleMessage | Downloads entire message from the currently selected IMAP4 mailbox. |
RetrieveSingleMessageHeaders | Downloads headers for the message from the currently selected IMAP4 mailbox. |
RetrieveTotalSize | Retrieves total size in bytes of all messages in the currently selected mailbox. |
Search | Searches the currently selected mailbox for messages that conform to specified criteria. |
SelectMailbox | Selects specified mailbox on the IMAP4 server. |
SendCommand | Executes user-supplied command on the IMAP4 server. |
SetFlagsForMessage | Sets the flags for specified message in the currently selected mailbox. |
SetFlagsForMessageAsString | Sets the flags for specified message in the currently selected mailbox, allowing for non-standard flags. |
Subscribe | Subscribes specified mailbox. |
ToUTF7 | Encodes the specified string into UTF-7M. |
Unsubscribe | Unsubscribes specified mailbox. |
Events | |
OnAlert | Fires when there is an [ALERT] message in the IMAP4 server response. |
OnEnvelopeDownloaded | Fires when IMAP4 object parses an envelope (FETCH response) in the data received from the IMAP server. |
OnIdle | Fires when another 10 millisecond period elapses during idling. |
OnReceiveData | Fires when the IMAP4 object receives new chunk of data from the IMAP server. |
OnStatusChange | Fires when mailbox status changes: new message has arrived, a message has been deleted, number of messages changes, and so on. |
Remarks
During the
development, it's recommended to enable logging the IMAP4 session into a file
by setting EnableLogging and LogFilePath properties. The log file
allows you to discover typical problems quickly and easily.
You can find more information on typical problems resolution in Troubleshooting
section of the IMAP4 samples.
Example
The following example retrieves new messages from the user account on the IMAP4 server, and displays each retrieved message. The sample is presented separately in Visual Basic version and ASP version since they differ quite enough.Dim objIMAP4, objMsg, arrNew, I ' Create IMAP4 object Set objIMAP4 = CreateObject("MailBee.IMAP4") ' Unlock IMAP4 object objIMAP4.LicenseKey = "put your license key here" ' Set IMAP4 server name objIMAP4.ServerName = "mail.server.com" ' Set user credentials objIMAP4.UserName = "username" objIMAP4.Password = "password" ' Connect to the server and ' log in email account If objIMAP4.Connect Then ' Select Inbox folder objIMAP4.SelectMailbox "Inbox" ' Get Unique-IDs of new messages arrNew = objIMAP4.Search(True, "new") ' Loop through new messages For I = LBound(arrNew) To UBound(arrNew) ' Completely retrieve message by its Unique-ID Set objMsg = objIMAP4.RetrieveSingleMessage(arrNew(I), True) ' Display the message MsgBox _ "From: " & objMsg.FromAddr & vbCrLf & _ "To: " & objMsg.ToAddr & vbCrLf & _ "Subject: " & objMsg.Subject & vbCrLf & _ "Date: " & objMsg.GetDateFromString(objMsg.Date) & vbCrLf & vbCrLf & _ objMsg.BodyText Next ' Close the connection objIMAP4.Disconnect End If
[ASP]
<% Dim objIMAP4, objMsg, arrNew, I ' Create IMAP4 object Set objIMAP4 = Server.CreateObject("MailBee.IMAP4") ' Unlock IMAP4 object objIMAP4.LicenseKey = "put your license key here" ' Set IMAP4 server name objIMAP4.ServerName = "mail.server.com" ' Set user credentials objIMAP4.UserName = "username" objIMAP4.Password = "password" ' Connect to the server and ' log in email account If objIMAP4.Connect Then ' Select Inbox folder objIMAP4.SelectMailbox "Inbox" ' Get Unique-IDs of new messages arrNew = objIMAP4.Search(True, "new") ' Loop through new messages For I = LBound(arrNew) To UBound(arrNew) ' Completely retrieve message by its Unique-ID Set objMsg = objIMAP4.RetrieveSingleMessage(arrNew(I), True) ' Display the message. ' We use Server.HTMLEncode to convert '<' and '>' ' characters which can disturb the output if they ' are contained in the message headers. Response.Write _ "From: " & Server.HTMLEncode(objMsg.FromAddr) & "<br>" & _ "To: " & Server.HTMLEncode(objMsg.ToAddr) & "<br>" & _ "Subject: " & Server.HTMLEncode(objMsg.Subject) & "<br>" & _ "Date: " & objMsg.GetDateFromString(objMsg.Date) & "<br><br>" & _ objMsg.BodyText Next ' Close the connection objIMAP4.Disconnect End If %>
See Also
Envelope Object, Message Object, RetrieveEnvelopes Method