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 BinData attachments.
  • Embed related HTML resources such as images or stylesheets.
  • Load an existing .eml or 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:

FeatureMembers
SenderFrom, FromAddress, FromName
Reply addressReplyTo
SubjectSubject
DateEmailDate, EmailDateStr, LocalDate, LocalDateStr
Mail client identifierMailer
Full MIME headerHeader

Recipients are added using methods such as:

Recipient TypeMethods
ToAddTo, AddMultipleTo, ClearTo
CCAddCC, AddMultipleCC, ClearCC
BCCAddBcc, 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:

TaskMembers
Set plain-text bodyBody, AddPlainTextAlternativeBody
Set HTML bodySetHtmlBody, AddHtmlAlternativeBody
Read plain-text bodyGetPlainTextBody, HasPlainTextBody
Read HTML bodyGetHtmlBody, GetHtmlBodySb, HasHtmlBody
Work with alternativesNumAlternatives, 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:

MemberPurpose
CharsetGets or sets the main charset of the email.
PreferredCharsetSuggests a preferred charset when Chilkat chooses one automatically.
LanguageIdentifies 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:

TaskMethods
Add a file attachmentAddFileAttachment, AddFileAttachment2
Add a byte-array attachmentAddDataAttachment, AddDataAttachment2
Add a string attachmentAddStringAttachment, AddStringAttachment2
Add a BinData attachmentAddAttachmentBd
Save attachmentsSaveAllAttachments, SaveAttachedFile
Remove attachmentsDropAttachments, DropSingleAttachment
Inspect attachmentsNumAttachments, GetAttachmentFilename, GetAttachmentContentType, GetAttachmentSize, GetAttachmentData, GetAttachmentBd
Rename or adjust attachmentsSetAttachmentFilename, 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:

TaskMethods / Properties
Add related filesAddRelatedFile, AddRelatedFile2
Add related dataAddRelatedData, AddRelatedData2, AddRelatedBd, AddRelatedBd2
Add related textAddRelatedString, AddRelatedString2
Count related itemsNumRelatedItems
Read related itemsGetRelatedFilename, GetRelatedContentID, GetRelatedContentType, GetRelatedData, GetRelatedString
Save related itemsSaveRelatedItem
Remove related itemsDropRelatedItem, 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 / SourceLoad Methods
EML fileLoadEml
MIME stringSetFromMimeText
MIME bytesSetFromMimeBytes, SetFromMimeBytes2
MIME BinDataSetFromMimeBd
MIME StringBuilderSetFromMimeSb
XML fileLoadXml
XML stringLoadXmlString, SetFromXmlText
Output FormatSave / Export Methods
EML fileSaveEml
MIME stringGetMime
MIME bytesGetMimeBinary
MIME BinDataGetMimeBd
MIME StringBuilderGetMimeSb
XML stringGetXml
XML fileSaveXml

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:

TaskMembers
Count matching MIME partsGetNumPartsOfType
Read Nth text partGetNthTextPartOfType
Read Nth binary partGetNthBinaryPartOfType, GetNthBinaryPartOfTypeBd
Get matching content typeGetNthContentType
Inspect headersNumHeaderFields, GetHeaderFieldName, GetHeaderFieldValue, GetHeaderField
Access alternative body headersGetAltHeaderField

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:

TaskMembers
Count attached messagesNumAttachedMessages
Retrieve attached messageGetAttachedEmail
Get attached message filenameGetAttachedMessageFilename
Remove attached messagesRemoveAttachedMessage, RemoveAttachedMessages
Attach another emailAttachEmail, 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:

TaskMembers
Detect multipart reportIsMultipartReport
Count reportsNumReports
Get report bodyGetReport
Get delivery status fieldGetDeliveryStatusInfo
Get DSN information as JSONGetDsnInfo

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

TaskMembers
Enable signingSendSigned
Enable encryptionSendEncrypted
Set signing certificateSetSigningCert, SetSigningCert2
Set encryption certificateSetEncryptCert, AddEncryptCert, ClearEncryptCerts
Choose signing hashSigningHashAlg
Choose signing algorithmSigningAlg
Choose PKCS7 encryption algorithmPkcs7CryptAlg
Choose PKCS7 key lengthPkcs7KeyLength

Receiving Signed or Encrypted Email

TaskMembers
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 certificateSetDecryptCert, SetDecryptCert2
Add PFX sourcesAddPfxSourceFile, 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:

MethodPurpose
AesEncryptEncrypts the email using a password.
AesDecryptDecrypts 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:

MemberPurpose
SetReplacePatternDefines a replacement pattern.
NumReplacePatternsReturns the number of defined patterns.
GetReplacePatternGets a pattern by index.
GetReplaceString / GetReplaceString2Gets 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:

FeatureMembers
EDIFACT email bodySetEdifactBody
iCalendar alternative bodyAddiCalendarAlternativeBody
Unique message filenameGenerateFilename
Global email keyComputeGlobalKey2
Linked domain extractionLinkedDomains
HTML unpackingAspUnpack, AspUnpack2, UnpackUseRelPaths
Fixing unusual MIME structureApplyFixups
Removing attachment pathsRemoveAttachmentPaths

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:

ClassResponsibility
Chilkat.EmailHolds and manipulates the email message.
Chilkat.MailManSends email and works with SMTP/POP3-style workflows.
Chilkat.ImapDownloads, 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.