C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

Examine Email MIME Structure

C# example code to create a complex email: one with file attachments, and HTML and plain-text alternative bodies, where the HTML includes embedded images. Then use Chilkat MIME to examine and display the MIME nesting structure.

    // This example builds a complex email:
    // -- one that has both plain-text and HTML alternative bodies.
    // -- the HTML has embedded images
    // -- there are multiple attachments.
    // We then examine the MIME structure using Chilkat MIME.

    private void traverseMime(Chilkat.Mime mime, int level)
    {
	string line = "";
	
	int i;
	for (i=0; i<level; i++)
	{
	    line = line + "----";
	}
	line = line + mime.ContentType;
	
	textBox1.Text = textBox1.Text + line + "\r\n";
	
	int n = mime.NumParts;
	for (i=0; i<n; i++)
	{
	    Chilkat.Mime part = mime.GetPart(i);
	    traverseMime(part,level+1);
	}
    }
    
    private void button6_Click(object sender, System.EventArgs e)
    {
	// First, we'll need the email component unlocked...
	Chilkat.MailMan mailman = new Chilkat.MailMan();
	mailman.UnlockComponent("anything for 30-day trial");

	// We'll convert a web page into an email with embedded
	// images.
	Chilkat.Mht mht = new Chilkat.Mht();
	mht.UnlockComponent("anything for 30-day trial");
	
	// Our URL was picked at random...
	Chilkat.Email email = mht.GetEmail("http://www.masukolandscaping.com/");
	
	// Add a plain-text alternative body.
	email.AddPlainTextAlternativeBody("this is the plain-text alternative...");
	
	// Add a few file attachments:
	email.AddFileAttachment("dude.gif");
	email.AddFileAttachment("blah.txt");
	
	// Now we have a complex email.  Get it as a MIME object and examine
	// the structure...
	Chilkat.Mime mime = new Chilkat.Mime();
	mime.UnlockComponent("anything for 30-day trial");
	
	mime = email.GetMimeObject();		
	mime.SaveMime("e.eml");
	
	textBox1.Text = "";
	traverseMime(mime,0);
	
	MessageBox.Show("Done!");
    }


This is the output:
The outermost MIME part is multipart/mixed. It has three sub-parts:
the two attachments and a multipart/related message.
The multipart/related contains a multipart/alternative and all
the images embedded within the HTML.  The multiplart/alternative
encloses the plain-text and HTML bodies.

multipart/mixed
----multipart/related
--------multipart/alternative
------------text/plain
------------text/html
--------image/gif
--------image/gif
--------image/gif
--------image/gif
--------image/gif
--------image/gif
--------image/jpeg
--------image/gif
--------image/gif
--------image/gif
--------image/gif
--------image/gif
----image/gif
----text/plain


Important: The download for this example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/csharp/step2.asp

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser