Chilkat Email Class Overview
The Chilkat.Email class represents a complete email message. It contains the message headers, sender and recipient fields, subject, body content, attachments, embedded HTML resources, attached messages, and security-related information such as S/MIME signing and encryption status.
The class is used to create, inspect, modify, load, save, and prepare email messages. It is typically used together with Chilkat mail transport classes, such as MailMan or Imap, which handle sending, receiving, and downloading messages.
Primary Purpose
Use Chilkat.Email when your application needs to:
- Build a new email message.
- Set the sender, recipients, subject, and body.
- Add plain-text and HTML bodies.
- Add file, string, byte-array, or
BinDataattachments. - Embed related HTML resources such as images or stylesheets.
- Load an existing
.emlor MIME message. - Inspect headers, recipients, attachments, and MIME parts.
- Save an email as EML, MIME, or XML.
- Work with S/MIME signed or encrypted email.
- Process delivery status notifications and multipart reports.
Message Headers and Addressing
The class provides properties and methods for working with common email header fields.
Common sender and addressing properties include:
| Feature | Members |
|---|---|
| Sender | From, FromAddress, FromName |
| Reply address | ReplyTo |
| Subject | Subject |
| Date | EmailDate, EmailDateStr, LocalDate, LocalDateStr |
| Mail client identifier | Mailer |
| Full MIME header | Header |
Recipients are added using methods such as:
| Recipient Type | Methods |
|---|---|
| To | AddTo, AddMultipleTo, ClearTo |
| CC | AddCC, AddMultipleCC, ClearCC |
| BCC | AddBcc, AddMultipleBcc, ClearBcc |
Recipient counts are available through NumTo, NumCC, and NumBcc.
Custom headers can be added with AddHeaderField or AddHeaderField2. Existing headers can be read with GetHeaderField, enumerated by index, or removed with RemoveHeaderField.
Email Bodies
An email may contain a plain-text body, an HTML body, or multiple alternative body formats.
The Body property provides convenient access to the body. If the email contains both HTML and plain text, Body returns the HTML body.
For more precise control, use:
| Task | Members |
|---|---|
| Set plain-text body | Body, AddPlainTextAlternativeBody |
| Set HTML body | SetHtmlBody, AddHtmlAlternativeBody |
| Read plain-text body | GetPlainTextBody, HasPlainTextBody |
| Read HTML body | GetHtmlBody, GetHtmlBodySb, HasHtmlBody |
| Work with alternatives | NumAlternatives, GetAlternativeBody, GetAlternativeContentType |
The class also supports iCalendar alternative bodies through AddiCalendarAlternativeBody, which is useful for meeting requests and calendar invitations.
Character Sets and Language Handling
Chilkat.Email includes charset-related properties for controlling how text is represented in MIME.
Important members include:
| Member | Purpose |
|---|---|
Charset | Gets or sets the main charset of the email. |
PreferredCharset | Suggests a preferred charset when Chilkat chooses one automatically. |
Language | Identifies the primary language group detected from the subject and body. |
Setting Charset can update both the MIME headers and, when possible, the HTML META charset information so that the message body and headers agree.
Attachments
The class provides extensive attachment support. Attachments can be added from files, strings, byte arrays, or BinData.
Common attachment methods include:
| Task | Methods |
|---|---|
| Add a file attachment | AddFileAttachment, AddFileAttachment2 |
| Add a byte-array attachment | AddDataAttachment, AddDataAttachment2 |
| Add a string attachment | AddStringAttachment, AddStringAttachment2 |
Add a BinData attachment | AddAttachmentBd |
| Save attachments | SaveAllAttachments, SaveAttachedFile |
| Remove attachments | DropAttachments, DropSingleAttachment |
| Inspect attachments | NumAttachments, GetAttachmentFilename, GetAttachmentContentType, GetAttachmentSize, GetAttachmentData, GetAttachmentBd |
| Rename or adjust attachments | SetAttachmentFilename, SetAttachmentCharset, SetAttachmentDisposition |
The OverwriteExisting property controls whether saved attachments overwrite existing files or are automatically renamed to avoid collisions.
Related Items for HTML Email
HTML email often includes embedded images, stylesheets, or other resources referenced from the HTML body. These are called related items. They are part of the message, but they are not treated as ordinary attachments because their purpose is to render the HTML content.
Related items are commonly used for inline images referenced by cid: URLs or by filenames in the HTML.
Useful members include:
| Task | Methods / Properties |
|---|---|
| Add related files | AddRelatedFile, AddRelatedFile2 |
| Add related data | AddRelatedData, AddRelatedData2, AddRelatedBd, AddRelatedBd2 |
| Add related text | AddRelatedString, AddRelatedString2 |
| Count related items | NumRelatedItems |
| Read related items | GetRelatedFilename, GetRelatedContentID, GetRelatedContentType, GetRelatedData, GetRelatedString |
| Save related items | SaveRelatedItem |
| Remove related items | DropRelatedItem, DropRelatedItems |
The ConvertInlineImages method can convert images embedded directly inside HTML into proper MIME related parts referenced by CID.
Loading and Saving Email
Chilkat.Email can load and save complete email messages in multiple formats.
| Format / Source | Load Methods |
|---|---|
| EML file | LoadEml |
| MIME string | SetFromMimeText |
| MIME bytes | SetFromMimeBytes, SetFromMimeBytes2 |
MIME BinData | SetFromMimeBd |
MIME StringBuilder | SetFromMimeSb |
| XML file | LoadXml |
| XML string | LoadXmlString, SetFromXmlText |
| Output Format | Save / Export Methods |
|---|---|
| EML file | SaveEml |
| MIME string | GetMime |
| MIME bytes | GetMimeBinary |
MIME BinData | GetMimeBd |
MIME StringBuilder | GetMimeSb |
| XML string | GetXml |
| XML file | SaveXml |
Loading an email replaces the current contents of the object, including recipients and headers.
MIME Inspection and Processing
The class exposes many methods for inspecting MIME structure directly. This is useful when working with complex messages, custom MIME parts, reports, embedded messages, or partially downloaded messages.
Examples include:
| Task | Members |
|---|---|
| Count matching MIME parts | GetNumPartsOfType |
| Read Nth text part | GetNthTextPartOfType |
| Read Nth binary part | GetNthBinaryPartOfType, GetNthBinaryPartOfTypeBd |
| Get matching content type | GetNthContentType |
| Inspect headers | NumHeaderFields, GetHeaderFieldName, GetHeaderFieldValue, GetHeaderField |
| Access alternative body headers | GetAltHeaderField |
Content-type matching can use exact values such as text/plain or wildcarded values such as text/ or .
Embedded Messages and Digests
Some email clients attach forwarded messages as embedded message/rfc822 parts. Chilkat.Email can detect and retrieve these attached messages.
Useful members include:
| Task | Members |
|---|---|
| Count attached messages | NumAttachedMessages |
| Retrieve attached message | GetAttachedEmail |
| Get attached message filename | GetAttachedMessageFilename |
| Remove attached messages | RemoveAttachedMessage, RemoveAttachedMessages |
| Attach another email | AttachEmail, AttachMessage |
The class also supports multipart digest messages through NumDigests and GetDigestEmail.
Delivery Reports and Multipart Reports
Chilkat.Email can process delivery status notifications and other multipart/report messages.
Useful members include:
| Task | Members |
|---|---|
| Detect multipart report | IsMultipartReport |
| Count reports | NumReports |
| Get report body | GetReport |
| Get delivery status field | GetDeliveryStatusInfo |
| Get DSN information as JSON | GetDsnInfo |
These methods are useful for analyzing bounce messages, delivery failures, feedback reports, and other server-generated email reports.
S/MIME Signing and Encryption
The class supports S/MIME signing, encryption, decryption, and signature validation.
Sending Signed or Encrypted Email
| Task | Members |
|---|---|
| Enable signing | SendSigned |
| Enable encryption | SendEncrypted |
| Set signing certificate | SetSigningCert, SetSigningCert2 |
| Set encryption certificate | SetEncryptCert, AddEncryptCert, ClearEncryptCerts |
| Choose signing hash | SigningHashAlg |
| Choose signing algorithm | SigningAlg |
| Choose PKCS7 encryption algorithm | Pkcs7CryptAlg |
| Choose PKCS7 key length | Pkcs7KeyLength |
Receiving Signed or Encrypted Email
| Task | Members |
|---|---|
| Was received signed? | ReceivedSigned |
| Was received encrypted? | ReceivedEncrypted |
| Was successfully decrypted? | Decrypted |
| Are signatures valid? | SignaturesValid |
| Who signed it? | SignedBy, LastSignerCert |
| What certificate decrypted it? | LastDecryptCert |
| Provide decrypt certificate | SetDecryptCert, SetDecryptCert2 |
| Add PFX sources | AddPfxSourceFile, AddPfxSourceData, AddPfxSourceBd |
The class can also use RSA-OAEP encryption options through OaepPadding, OaepHash, and OaepMgfHash.
Password-Based AES Encryption
In addition to S/MIME, the class includes Chilkat-specific password-based AES encryption:
| Method | Purpose |
|---|---|
AesEncrypt | Encrypts the email using a password. |
AesDecrypt | Decrypts an email previously encrypted with AesEncrypt. |
This is not certificate-based S/MIME encryption. Both sender and receiver must use Chilkat and must know the same password.
Mail Merge and Replacement Patterns
Chilkat.Email includes a simple mail-merge style replacement feature.
Use SetReplacePattern to define pattern/replacement pairs. During sending, Chilkat can replace those patterns in headers and body content.
Useful members include:
| Member | Purpose |
|---|---|
SetReplacePattern | Defines a replacement pattern. |
NumReplacePatterns | Returns the number of defined patterns. |
GetReplacePattern | Gets a pattern by index. |
GetReplaceString / GetReplaceString2 | Gets the replacement value. |
Pattern replacement occurs during mail sending or MIME rendering by the mail-sending class. Methods such as SaveEml and GetMime do not apply replacement patterns.
Specialized Message Features
The class also supports several specialized workflows:
| Feature | Members |
|---|---|
| EDIFACT email body | SetEdifactBody |
| iCalendar alternative body | AddiCalendarAlternativeBody |
| Unique message filename | GenerateFilename |
| Global email key | ComputeGlobalKey2 |
| Linked domain extraction | LinkedDomains |
| HTML unpacking | AspUnpack, AspUnpack2, UnpackUseRelPaths |
| Fixing unusual MIME structure | ApplyFixups |
| Removing attachment paths | RemoveAttachmentPaths |
Error Information
Most Chilkat methods return true for success and false for failure. When a method fails, check:
email.LastErrorText
LastErrorText provides detailed diagnostic information about the most recent method or property call. It is often useful even when a method succeeds, because it can contain additional details about what occurred internally.
Relationship to MailMan, IMAP, and POP3
Chilkat.Email represents the message itself. It does not perform SMTP, POP3, or IMAP communication on its own.
Typical usage looks like this:
| Class | Responsibility |
|---|---|
Chilkat.Email | Holds and manipulates the email message. |
Chilkat.MailMan | Sends email and works with SMTP/POP3-style workflows. |
Chilkat.Imap | Downloads, searches, and manages email on IMAP servers. |
For example, an application may use Imap to download a message, then use Email to inspect its attachments, body, headers, signatures, or MIME structure.
Summary
Chilkat.Email is the central Chilkat class for working with email message content and structure. It provides high-level features for ordinary email composition, plus lower-level access to MIME parts, headers, attachments, related items, embedded messages, delivery reports, and S/MIME security.
Use this class whenever your application needs to build, parse, modify, save, inspect, sign, encrypt, decrypt, or otherwise work with an email message.