---
product: Chilkat
product_version: 11.7.0
language: asp
language_label: Classic ASP
class: EmailBundle
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/asp_EmailBundleRef.html
---
# Chilkat EmailBundle — Classic ASP — v11.7.0

> Chilkat 11.7.0 · language=asp · class=EmailBundle
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/EmailBundle.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/asp/guide.md`.

## Purpose

EmailBundle

**Hold, search, sort, remove, save, and reload groups of email messages.**

`EmailBundle` is a container for multiple `Email` objects. It is commonly returned by mail-related operations and can also be built manually by adding individual email messages. The class provides a simple way to work with groups of messages: retrieve emails by index, search for a matching email, sort by common email fields, remove messages, clear the bundle, and serialize or reload the collection as XML.

**Email collection**

Store multiple `Email` objects together after receiving, loading, filtering, or manually building a message set.

**Retrieve messages**

Use the message count and indexed access methods to retrieve individual emails for inspection, processing, saving, or sending.

**Search within the bundle**

Locate a specific email in the collection when application logic needs to find a matching message.

**Sort messages**

Sort the bundle by date, sender, recipient, or subject to organize messages before processing or display.

**Remove or clear emails**

Remove individual messages by object or index, or clear the entire bundle when the collection is no longer needed.

**Save and reload**

Serialize the bundle to XML and reload it later, or load task results that return an email bundle.

**Common pattern:** Receive or build a bundle of `Email` objects, loop from `0` to `MessageCount - 1`, retrieve each message with `EmailAt`, and then inspect, save, sort, remove, or process each email as needed. Use `EmailBundle` for the group and `Email` for the individual message contents.

For an extended overview, see [EmailBundle Class Overview](https://www.chilkatsoft.com/emailbundle_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```visual-basic
set emailBundle = Server.CreateObject("Chilkat.EmailBundle")

' ... use emailBundle ...

set emailBundle = Nothing
```

Classic ASP creates Chilkat objects with `Server.CreateObject`. The registered Chilkat ActiveX must match the bitness of the IIS application pool: a pool with *Enable 32-Bit Applications* set to True needs the 32-bit ActiveX, otherwise the 64-bit ActiveX. To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `Server.CreateObject("Chilkat.EmailBundle.11")` for Chilkat v11.\*.\*.

VBScript requires `set` when assigning an object, so the signatures on this page show `set x = obj.Method(...)` for methods that return a Chilkat object; test the result with `Is Nothing`, since a method that fails to return an object returns `Nothing`. A method with no return value is called as a statement without parentheses (`obj.Method arg1, arg2`). Boolean properties, arguments and return values are integers in the ActiveX: pass `1` or `0`, and test success with `= 1`. Byte arrays are Variant arrays and can be sent with `Response.BinaryWrite`. Asynchronous (*\*Async*) methods and event callbacks are not used from Classic ASP.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in Classic ASP.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `emailBundle.DebugLogFilePath ' String` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `emailBundle.LastBinaryResult ' Variant (read-only)` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `emailBundle.LastErrorHtml ' String (read-only)` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `emailBundle.LastErrorText ' String (read-only)` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `emailBundle.LastErrorXml ' String (read-only)` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `emailBundle.LastMethodSuccess ' Long` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `emailBundle.LastStringResult ' String (read-only)` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `emailBundle.LastStringResultLen ' Long (read-only)` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `emailBundle.VerboseLogging ' Long` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `emailBundle.Version ' String (read-only)` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `MessageCount` | property, read-only | `emailBundle.MessageCount ' Long (read-only)` |
| `AddEmail` | method | `success = emailBundle.AddEmail(email) ' Long (1/0)` |
| `Clear` | method | `emailBundle.Clear` |
| `EmailAt` | method | `success = emailBundle.EmailAt(index, email) ' Long (1/0)` |
| `FindEmail` | method | `success = emailBundle.FindEmail(json, email) ' Long (1/0)` |
| `GetXml` | method | `str = emailBundle.GetXml() ' String` |
| `LoadXml` | method | `success = emailBundle.LoadXml(path) ' Long (1/0)` |
| `LoadXmlString` | method | `success = emailBundle.LoadXmlString(xmlStr) ' Long (1/0)` |
| `RemoveEmail` | method | `success = emailBundle.RemoveEmail(email) ' Long (1/0)` |
| `RemoveEmailByIndex` | method | `success = emailBundle.RemoveEmailByIndex(index) ' Long (1/0)` |
| `SaveXml` | method | `success = emailBundle.SaveXml(path) ' Long (1/0)` |
| `SortByDate` | method | `emailBundle.SortByDate ascending` |
| `SortByRecipient` | method | `emailBundle.SortByRecipient ascending` |
| `SortBySender` | method | `emailBundle.SortBySender ascending` |
| `SortBySubject` | method | `emailBundle.SortBySubject ascending` |

Deprecated members are listed at the end of this file with their replacements; do not use them in new code.

## Properties

### EmailBundle.MessageCount

`Chilkat 11.7.0 · asp · EmailBundle · MessageCount · property · read-only`

```visual-basic
emailBundle.MessageCount  ' Long (read-only)
```

Returns the number of `Email` objects currently contained in the bundle.

Valid zero-based indexes range from `0` through `MessageCount - 1`.

## Methods

### EmailBundle.AddEmail

`Chilkat 11.7.0 · asp · EmailBundle · AddEmail · method`

```visual-basic
success = emailBundle.AddEmail(email)  ' Long (1/0)
```

Adds an independent copy of the `Email` object in `email` to the end of this in-memory bundle.

The bundle does not retain a reference to `email` and does not take ownership of the supplied object. Changes made to `email` after this method returns do not affect the copy stored in the bundle, and changes to the stored copy do not affect `email`.

The same `Email` object may be added more than once. Each call adds another independent copy and increases the `MessageCount` property by one.

Returns 1 for success, 0 for failure.

### EmailBundle.Clear

`Chilkat 11.7.0 · asp · EmailBundle · Clear · method · since 11.1.0`

```visual-basic
emailBundle.Clear
```

Removes and discards all emails from this in-memory bundle.

After this method returns, `MessageCount` is `0`. No messages are deleted from any mail server.

### EmailBundle.EmailAt

`Chilkat 11.7.0 · asp · EmailBundle · EmailAt · method · since 11.0.0`

```visual-basic
success = emailBundle.EmailAt(index, email)  ' Long (1/0)
```

Copies the email at the zero-based index in `index` into the `Email` object in `email`.

Valid indexes range from `0` through `MessageCount - 1`. The first email is at index `0`.

`email` receives an independent copy. Changes made to `email` do not modify the email stored in the bundle.

**Note:** This is an in-memory operation and does not communicate with a mail server.

Returns 1 for success, 0 for failure.

### EmailBundle.FindEmail

`Chilkat 11.7.0 · asp · EmailBundle · FindEmail · method · since 11.0.0`

```visual-basic
success = emailBundle.FindEmail(json, email)  ' Long (1/0)
```

Finds the first email in the bundle whose MIME header field matches the search criteria specified by the `JsonObject` in `json`.

At this time, a search may specify only one MIME header field. Use the following JSON format:

```
{
  "header": {
    "name": "Subject",
    "value": "Dinner on Wednesday?",
    "caseInsensitive": true
  }
}
```

`header.name` specifies the MIME header field name, and `header.value` specifies the complete field value to match. The field value must match exactly; this is not a substring, wildcard, or regular-expression search. Set `header.caseInsensitive` to `true` for a case-insensitive comparison or `false` for a case-sensitive comparison.

When a match is found, `email` receives the first matching email.

Returns 1 for success, 0 for failure.

### EmailBundle.GetXml

`Chilkat 11.7.0 · asp · EmailBundle · GetXml · method`

```visual-basic
str = emailBundle.GetXml()  ' String
```

Serializes the entire email bundle to Chilkat XML and returns the XML document as a string.

The XML contains the bundle and its individual `Email` objects. It can be loaded into another `EmailBundle` by calling `LoadXmlString`.

This is Chilkat's XML representation of an email bundle; it is not an RFC 822/MIME message.

Returns `Nothing` on failure

### EmailBundle.LoadXml

`Chilkat 11.7.0 · asp · EmailBundle · LoadXml · method`

```visual-basic
success = emailBundle.LoadXml(path)  ' Long (1/0)
```

Loads an email bundle from the local filesystem path specified by `path`. The path may be absolute or relative; a filename alone refers to a file in the current working directory.

The file should contain Chilkat email-bundle XML previously produced by `SaveXml` or `GetXml`.

The emails loaded from `path` are appended to the emails already in the bundle. Existing emails are not removed or replaced.

Returns 1 for success, 0 for failure.

### EmailBundle.LoadXmlString

`Chilkat 11.7.0 · asp · EmailBundle · LoadXmlString · method`

```visual-basic
success = emailBundle.LoadXmlString(xmlStr)  ' Long (1/0)
```

Loads an email bundle from the Chilkat XML string in `xmlStr`.

The XML is typically obtained from `GetXml` or read from a file created by `SaveXml`.

The emails loaded from `xmlStr` are appended to the emails already in the bundle. Existing emails are not removed or replaced.

Returns 1 for success, 0 for failure.

### EmailBundle.RemoveEmail

`Chilkat 11.7.0 · asp · EmailBundle · RemoveEmail · method`

```visual-basic
success = emailBundle.RemoveEmail(email)  ' Long (1/0)
```

Removes the first email in this in-memory bundle that matches `email`.

Chilkat first searches for an email having the same UIDL as `email`. If no email with a matching UIDL is found, it searches for the first email having the same `Message-ID` header field value. Only the first matching email is removed.

`email` may be an independent copy obtained from `EmailAt`.

**Note:** This method changes only the local bundle. It does not delete a message from a POP3 or IMAP server.

Returns 1 for success, 0 for failure.

### EmailBundle.RemoveEmailByIndex

`Chilkat 11.7.0 · asp · EmailBundle · RemoveEmailByIndex · method`

```visual-basic
success = emailBundle.RemoveEmailByIndex(index)  ' Long (1/0)
```

Removes the email at the zero-based index in `index`.

Valid indexes range from `0` through `MessageCount - 1`.

**Note:** This method changes only the local bundle. It does not delete a message from a mail server.

Returns 1 for success, 0 for failure.

### EmailBundle.SaveXml

`Chilkat 11.7.0 · asp · EmailBundle · SaveXml · method`

```visual-basic
success = emailBundle.SaveXml(path)  ' Long (1/0)
```

Serializes the bundle and each contained `Email` to Chilkat XML, then writes the XML document to the local filesystem path specified by `path`. The path may be absolute or relative; a filename alone writes to the current working directory.

Reload the saved bundle by calling `LoadXml`. Use `GetXml` when the XML is needed in memory rather than in a file.

The saved file is a Chilkat email-bundle serialization, not an RFC 822/MIME message file.

Returns 1 for success, 0 for failure.

### EmailBundle.SortByDate

`Chilkat 11.7.0 · asp · EmailBundle · SortByDate · method`

```visual-basic
emailBundle.SortByDate ascending
```

Sorts the emails in this bundle by each `Email` object's `EmailDate` property.

Set `ascending` to `1` to sort in ascending order, from oldest to newest. Set `ascending` to `0` to sort in descending order, from newest to oldest.

The operation changes the order of the emails in the in-memory collection.

### EmailBundle.SortByRecipient

`Chilkat 11.7.0 · asp · EmailBundle · SortByRecipient · method`

```visual-basic
emailBundle.SortByRecipient ascending
```

Sorts the emails in this bundle by the full value of each email's `To` header field.

The comparisons are case-sensitive. Set `ascending` to `1` for ascending order or `0` for descending order. The operation changes the order of the emails in the in-memory collection.

### EmailBundle.SortBySender

`Chilkat 11.7.0 · asp · EmailBundle · SortBySender · method`

```visual-basic
emailBundle.SortBySender ascending
```

Sorts the emails in this bundle by the full content of each email's `From` header field.

Set `ascending` to `1` for ascending order or `0` for descending order. The operation changes the order of the emails in the in-memory collection.

### EmailBundle.SortBySubject

`Chilkat 11.7.0 · asp · EmailBundle · SortBySubject · method`

```visual-basic
emailBundle.SortBySubject ascending
```

Sorts the emails in this bundle by subject.

Set `ascending` to `1` for ascending order or `0` for descending order. The operation changes the order of the emails in the in-memory collection.

## Deprecated members — do not use in new code

| Member | Kind | Deprecated in | Use instead |
|---|---|---|---|
| `AddMimeBytes` | method | before 11.6.1 | — |
| `FindByHeader` | method | before 11.6.1 | `FindEmail` |
| `GetEmail` | method | before 11.6.1 | `EmailAt` |
| `GetUidls` | method | before 11.6.1 | — |

## Related classes

[`Email`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/asp/classes/Email.md), [`JsonObject`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/asp/classes/JsonObject.md)

