Version: 3.0.3.2
Securely send, receive, preview, edit, sign/verify, and encrypt/decrypt email messages in any .NET project. 

MessageStream Class (Encode and Decode MIME messages)

The MessageStream class represents a MIME, Secure MIME (S/MIME), or non-MIME Internet email message. Writing to the object populates collections of decoded parts. Reading from the object encodes the message "on the fly".

MessageStream is used by the Smtp component to encode email messages and by the Pop and Imap components to decode received email messages. MessageStream can also be used independently as a general purpose S/MIME encoder and decoder. Messages are always encoded/decoded "on the fly" (supported encoding types include Base64, Quoted Printable, UUEncode, and Yencode), which both increases the speed of processing and eliminates use of temporary files in encoding/decoding. Every MIME attachment, MIME part, and label element is represented as an object, giving you unsurpassed processing convenience.

Integrates with all versions of Visual Studio and supports C#, VB.NET, ASP.NET, Delphi 8, C# Builder, and other .NET compliant development environments.

Looking for the ActiveX version of this class?

Interface

Public Constructors
MessageStream Overloaded. Initialize a new instance of the MessageStream class.
Public Properties
Attachments Gets a collection containing all recursive attachments contained within the message
BCC Gets a MailAddresses collection of blind carbon copy recipients.
CanRead Gets a value indicating whether the current Stream supports reading.
CanSeek Gets a value indicating whether the current Stream supports seeking.
CanWrite Gets a value indicating whether the current Stream supports writing.
CC Gets a value indicating whether the current Stream supports writing.
Charset
Date Sets the "DATE:" header field in the message.
From Gets or sets the MailAddress object which specifies who the email is from.
Header Gets or sets a MailHeader collection representing the mail header lines of the message. Inherits from ArrayList.
IsSmime Gets a value that indicates whether the message is an encoded S/MIME message.
Length Gets the length in bytes of the stream.
Mailer Sets the "X-MAILER:" header field in the message.
MimeBoundary Gets or sets the boundary between MIME parts.
NonMime Gets a NonMime class representing non-MIME message parts.
Parts Gets a Parts class representing MIME parts in the message.
Position Gets or sets the current position of this stream.
ReturnReceiptTo Sets the "RETURN-RECEIPT-TO:" header field in the message.
Subject Sets the "SUBJECT:" header field in the message.
Text Gets or sets the text for the message.
To Gets a MailAddresses collection of normal recipients.
Type Gets or sets the "Content-Type" header of the message or part.
Public Methods
Clone Creates a shallow copy of the MessageStream.
Flush Updates the underlying data source or repository with the current state of the buffer and then clears the buffer.
Forward Overloaded. Returns a MessageStream object formatted for a forwarded message.
Read Overloaded. Reads at least one byte of data from the Stream and copies it into the provided buffer.
Reply Overloaded. Returns a MessageStream object formatted for a reply message.
Seek Sets the position within the current Stream to the specified value. Always throws a NotSupportedException.
SetLength Sets the length of the current Stream to the specified value. Always throws a NotSupportedException.
Store Overloaded. Stores the encoded MessageStream to the provided Stream.
ToArray Returns a byte array representation of the encoded message.
ToMime Converts an S/MIME message into it's decoded form. Optionally returns signing and decrypting certificates.
ToSmime Converts a MIME message into it's encoded S/MIME form. Optionally returns signing and encrypting certificates.
ToString Returns a string representation of the encoded message.
Write Overloaded. Writes a sequence of bytes to the Stream and returns when the operation is complete.

Code Example

How easy is the MessageStream object to use? The following example demonstrates creating and sending an S/MIME email message.

VB.NET Example
' Create an instance of the MessageStream object
Dim msg As New MessageStream()

' Set "To", "From", and "Subject"
msg.To.Add(New MailAddress("you@yourserver.com"))
msg.From = New MailAddress("me@myserver.com")
msg.Subject = "Test Message"

' Set the message text
msg.Text = "This is a test message"

' Add an attachment to the message, it will automatically be encoded.
msg.Attachments.Add("C:\myfiles\myattachment.txt");

' Now mail the message using the Smtp component...First set the server.
Smtp1.Server = "mail.test.com"

' Then sign and send the S/MIME message
Smtp1.Send(msg.ToSmime())