Wednesday, June 28, 2017 
   home about us faq contact us
PRODUCT
FAQ
Licensing
Overview
Spam Checking
EVALUATION
Download
PURCHASE
Buy Now
Shopping Cart
SUPPORT
Class Reference
Examples
Mailing List
Support Form
OTHER EMAIL
PRODUCTS
aspNetEmail
aspNetMime
aspNetMHT
aspNetMX
aspNetPOP3
ListNanny
NETWORKING
PRODUCTS
aspNetDns
aspNetPing
aspNetTraceRoute 
aspNetWhois

 
 
Examples and Documentation

Documentation
    Online Help
    Downloadable .chm Help File

Support
    Email support@advancedIntellect.com
    Telephone Support

Online Forums
    Yahoo "Anything .NET and Email" Peer Support Group

Examples

 

Logging with aspNetIMAP
The following example demonstrates creating an IMAP session log.

There are two basic ways of logging. One is to actually create a text file. The following example creates a text file log at c:\imap.log. If you do not have write permissions to create a file, you can always keep a log in memory. The following example also demonstrates keeping an in-memory log.

[ C# ]
IMAP4 imap = new IMAP4( "127.0.0.1" );
imap.Logger = new IMAPLog();

//if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\\imap.log";

//if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = true;

imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();

//list all of the folders
MailFolderCollection mfc = imap.FolderList();
Console.WriteLine( mfc.ToString() );

//write out the log
Console.WriteLine( imap.Logger.ToString() );

imap.Disconnect();

Console.WriteLine( "Done" );
Console.ReadLine();
[ VB.NET ]
Dim imap As New IMAP4("127.0.0.1")
imap.Logger = New IMAPLog()

'if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\imap.log"

'if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = True

imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()

'list all of the folders
Dim mfc As MailFolderCollection = imap.FolderList()
Console.WriteLine(mfc.ToString())

'write out the log
Console.WriteLine(imap.Logger.ToString())

imap.Disconnect()

Console.WriteLine("Done")
Console.ReadLine()

Download Headers
The following example demonstrates using aspNetIMAP to download a message's headers

A note about Message Indexes
There are two numbering systems to reference messages in the mail folder. Messages can be referenced by their ordinal position (i.e. 1, 2, 3, 4) , or by a unique identifier (UID). To convert an Ordinal message set to a UniqueId message set, check out MessageClient.ToUniqueId().

Multiple message numbers can be separated by commas or can be designated with a '*', which refers to the highest message number in the mail folder. A pair of numbers, separated by a ':', indicates a contiguous set of messages ranging from the first message number to the second. These ranges of message numbers are called 'message sets'. Message numbers, referenced by their ordinal index, are always ascending and always contiguous.

As an example, here are some message sets, and the respective messages they represent. All of the numbers used in this example, reference the messages by their ordinal index. This example also assumes there are 7 messages in the mail folder.

MessageSet Actual Message Numbers
1 1
2, 5 2 5
1:* 1 2 3 4 5 6 7
5:* 5 6 7
1,2,5,7 1 2 5 7
2:5 2 3 4 5
1,3:5,7 1 3 4 5 7
1:3, 5:7 1 2 3 5 6 7
1,3:5,6:* 1 3 4 5 6 7

These properly formatted message sets can be used when various aspNetIMAP methods accept the messageSet parameter. Although this example uses Ordinal Indexes, the same technique (using commas ',' and asterisks '*' ) can be used with UID's (Unique Identifiers).

[ C# ]
IMAP4 imap = new IMAP4( "127.0.0.1" );

imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();

//grab the inbox
MailFolder mf = imap.SelectInbox();

//download the first message's headers
string headers = mf.FetchClient.Headers( 1, IndexType.Ordinal );

Console.WriteLine( headers );

imap.Disconnect();


Console.WriteLine( "Done" );
Console.ReadLine();
[ VB.NET ]
Dim imap As New IMAP4("127.0.0.1")

imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()

'grab the inbox
Dim mf As MailFolder = imap.SelectInbox()

'download the first message's headers
Dim headers As String = mf.FetchClient.Headers(1, IndexType.Ordinal)

Console.WriteLine(headers)

imap.Disconnect()


Console.WriteLine("Done")
Console.ReadLine()

Downloading Folders as Xml
The following example demonstrates using aspNetIMAP to output a list of Folders to XML.

[ C# ]
IMAP4 imap = new IMAP4( "127.0.0.1" );
 
imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();
 
//list all of the folders
MailFolderCollection mfc = imap.FolderList();
 
imap.Disconnect();
 
//write out the collection as a string
Console.WriteLine( mfc.ToXmlString() );
 
Console.WriteLine( "Done" );
Console.ReadLine();
[ VB.NET ]
Dim imap As New IMAP4("127.0.0.1")
 
imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()
 
'list all of the folders
Dim mfc As MailFolderCollection = imap.FolderList()
 
imap.Disconnect()
 
'write out the collection as a string
Console.WriteLine(mfc.ToXmlString())
 
Console.WriteLine("Done")
Console.ReadLine();

Downloading a Message
The following example demonstrates using aspNetIMAP to download a message as text.

[ C# ]
IMAP4 imap = new IMAP4( "127.0.0.1", "dave@blah.com", "test"  );  

imap.Login();  

//fetch the first message of the inbox
MailFolder mf = imap.SelectInbox();
string text = mf.FetchClient.MessageAsText( 1, IndexType.Ordinal );

Console.WriteLine( text );

imap.Disconnect();  


Console.WriteLine( "Done" );  
Console.ReadLine();
[ VB.NET ]
Dim imap As New IMAP4("127.0.0.1", "dave@blah.com", "test")

imap.Login()

'fetch the first message of the inbox
Dim mf As MailFolder = imap.SelectInbox()
Dim [text] As String = mf.FetchClient.MessageAsText(1, IndexType.Ordinal)

Console.WriteLine([text])

imap.Disconnect()


Console.WriteLine("Done")
Console.ReadLine()

Checking a message for spam
aspNetIMAP uses the DNS black list (DNSbl) technique to check if a message is marked as spam. More information on this can be found here. The following example demonstrates checking a messages against Spamhaus and Sorbs DNSbl servers.

[ C# ]
IMAP4 imap = new IMAP4( "127.0.0.1" );
imap.Logger = new IMAPLog();

//if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\\imap.log";

//if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = true;

imap.Username = "dave@blah.com";
imap.Password = "test";
imap.Login();

MailFolder inbox = imap.SelectInbox();

//load the BlackListChecker with 2 databases: spamhaus and sorbs
imap.BlackListChecker.AddDNSBlackList( "sbl-xbl.spamhaus.org", "127.0.0.2" );
imap.BlackListChecker.AddDNSBlackList( "dnsbl.sorbs.net", "127.0.0.2, 127.0.0.3, 127.0.0.4, 
127.0.0.5, 127.0.0.6, 127.0.0.7, 127.0.0.8, 127.0.0.9, 127.0.0.10, 127.0.0.11, 127.0.0.12" );

//check to see if the first message is spam
bool result = inbox.MessageClient.IsBlackListedSpam( 1, IndexType.Ordinal, false );
Console.WriteLine( result );

//write out the log
Console.WriteLine( imap.Logger.ToString() );

imap.Disconnect();

Console.WriteLine( "Done" );
Console.ReadLine();
[ VB.NET ]
Dim imap As New IMAP4("127.0.0.1")
imap.Logger = New IMAPLog()

'if we have write permissions to the filesystem, we can write out a physical log file
imap.Logger.Path = "c:\imap.log"

'if we don't have write permissions to a file, we can always keep an in-memory log
imap.Logger.InMemory = True

imap.Username = "dave@blah.com"
imap.Password = "test"
imap.Login()

Dim inbox As MailFolder = imap.SelectInbox()

'load the BlackListChecker with 2 databases: spamhaus and sorbs
imap.BlackListChecker.AddDNSBlackList("sbl-xbl.spamhaus.org", "127.0.0.2")
imap.BlackListChecker.AddDNSBlackList("dnsbl.sorbs.net", "127.0.0.2, 127.0.0.3, 127.0.0.4, 
127.0.0.5, 127.0.0.6, 127.0.0.7, 127.0.0.8, 127.0.0.9, 127.0.0.10, 127.0.0.11, 127.0.0.12")

'check to see if the first message is spam
Dim result As Boolean = inbox.MessageClient.IsBlackListedSpam(1, IndexType.Ordinal, False)
Console.WriteLine(result)

'write out the log
Console.WriteLine(imap.Logger.ToString())

imap.Disconnect()

Console.WriteLine("Done")
Console.ReadLine()

 

 

 






  "This is my FAVORITE component. Great Work !!"
James Hampton
Bellsouth
 
More Testimonials

OTHER PRODUCTS
Click here to learn more +  
    © AdvancedIntellect
All rights reserved