Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Downloads
.NET 2.0
.NET 1.*
.NET x64
VC++ 6.0
VC++ 7.0
VC++ 8.0
Java
Ruby
Perl 5.8.*
Perl 5.10.*
Python
Bounce ActiveX
Charset ActiveX
Email ActiveX
FTP2 ActiveX
Crypt ActiveX
HTML-to-XML ActiveX
HTTP ActiveX
IMAP ActiveX
MHT ActiveX
MIME ActiveX
RSA ActiveX
Socket ActiveX
Spider ActiveX (free)
String ActiveX (free)
Tar ActiveX
Upload ActiveX (free)
XML ActiveX (free)
XMP ActiveX
Zip ActiveX

Index of Chilkat Blog Posts

March 19, 2008

Loading an Email Object from a Byte Array

This C# example demonstrates how to load an email object from a byte array:

private void LoadEmailFromByteArray()
{
    // First, load an email from a file into a byte array.
    // (This example really begins after we have the exact bytes
    // from the file in a byte array.)
    byte[] emailBytes = System.IO.File.ReadAllBytes("email.eml");
	
    // There are two approaches.
    // (1) Convert the byte array to a string and then call
    // Chilkat.Email.SetFromMimeText to load it into an email object.
    // However, if an 8bit encoding is used, you'll need to know
    // the character encoding in order to convert the bytes to
    // a string. This is the reason for 7bit (quoted-printable) encodings
    // in MIME -- so you don't have to deal with this mess.
    // If the content-type of each part within the MIME is quoted-printable
    // or base64, you can assume us-ascii.
    //
    // (2) A second approach is to use Chilkat.Mime to load the byte array
    // into a Chilkat.Mime object and then convert that to a Chilkat.Email
    // object.  The Chilkat.Mime object provides a LoadMimeBytes method intended
    // to handle binary MIME and MIME with 8bit content-types.
    // 
	
    // Approach #1: Convert to a string and load into a Chilkat.Email object:
    string mimeStr = System.Text.Encoding.ASCII.GetString(emailBytes);
	
    Chilkat.Email email = new Chilkat.Email();
    email.SetFromMimeText(mimeStr);
	
    // Approach #2: Load bytes into Chilkat.Mime, then convert to Chilkat.Email:
    Chilkat.Mime mime = new Chilkat.Mime();
    // The following two methods return true/false success statuses, and they really should be checked...
    mime.UnlockComponent("Anything for 30-day trial");
    mime.LoadMimeBinary(emailBytes);
    email.SetFromMimeObject(mime);
	
}
	


Privacy Statement. Copyright 2000-2008 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, and Windows 95/98/NT4.