<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lesnikowski Blog &#187; VB.NET</title>
	<atom:link href="http://www.lesnikowski.com/blog/index.php/tag/vb-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lesnikowski.com/blog</link>
	<description>.Net</description>
	<lastBuildDate>Wed, 28 Jul 2010 10:10:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sign emails with DKIM</title>
		<link>http://www.lesnikowski.com/blog/index.php/sign-emails-with-dkim/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sign-emails-with-dkim</link>
		<comments>http://www.lesnikowski.com/blog/index.php/sign-emails-with-dkim/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 16:05:02 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DKIM]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1008</guid>
		<description><![CDATA[DKIM is short for DomainKeys Identified Mail. 
Adding a signature looks like this:

// C#

using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
   IMail email = Mail
       .Text(&#34;text&#34;)
       .From(&#34;alice@mail.com&#34;)
       .To(&#34;bob@mail.com&#34;)
       .Subject(&#34;subject&#34;)
   [...]]]></description>
			<content:encoded><![CDATA[<p>DKIM is short for DomainKeys Identified Mail. </p>
<p>Adding a signature looks like this:</p>
<pre class="brush: csharp;">
// C#

using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
   IMail email = Mail
       .Text(&quot;text&quot;)
       .From(&quot;alice@mail.com&quot;)
       .To(&quot;bob@mail.com&quot;)
       .Subject(&quot;subject&quot;)
       .DKIMSign(rsa, &quot;brisbane&quot;, &quot;example.com&quot;)
       .Create();
}
</pre>
<pre class="brush: vb;">
' VB.NET

Using rsa As New RSACryptoServiceProvider()
	Dim email As IMail = Mail _
		.Text(&quot;text&quot;) _
		.From(&quot;alice@mail.com&quot;) _
		.[To](&quot;bob@mail.com&quot;) _
		.Subject(&quot;subject&quot;) _
		.DKIMSign(rsa, &quot;brisbane&quot;, &quot;example.com&quot;) _
		.Create()
End Using
</pre>
<p>So what you need is RSACryptoServiceProvider with your private key, and two strings: selector and domain.</p>
<p>Basically how this works is the recipient of the email queries the DNS server for TXT record for selector._domainkey.domain (in our sample it is: &#8220;brisbane._domainkey.example.com&#8221;) to get the public key and validate the signature.</p>
<p>You can use <strong>nslookup </strong>to get the public key for a domain:</p>
<pre class="brush: plain;">
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Pawel&gt;nslookup
Default Server:  UnKnown
Address:  192.168.0.1

&gt; set type=TXT
&gt; gamma._domainkey.gmail.com
Server:  UnKnown
Address:  192.168.0.1

Non-authoritative answer:
gamma._domainkey.gmail.com      text =

        &quot;k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrI
Ve9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBD
jiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB&quot;

gmail.com       nameserver = ns1.google.com
gmail.com       nameserver = ns4.google.com
gmail.com       nameserver = ns3.google.com
gmail.com       nameserver = ns2.google.com
ns1.google.com  internet address = 216.239.32.10
ns2.google.com  internet address = 216.239.34.10
ns3.google.com  internet address = 216.239.36.10
ns4.google.com  internet address = 216.239.38.10
&gt;
</pre>
<p>But don&#8217;t worry as <strong>Mail.dll will make this DNS </strong>query for you.</p>
<p>Validating (including DNS query for public key) is simple:</p>
<pre class="brush: csharp;">
// C#

IMail email = new MailBuilder()
    .CreateFromEmlFile(&quot;signed_gamma.gmail.eml&quot;);
bool isValid = email.CheckDKIMSignature();
</pre>
<pre class="brush: vb;">
' VB.NET

Dim email As IMail = New MailBuilder() _
    .CreateFromEmlFile(&quot;signed_gamma.gmail.eml&quot;)
Dim isValid As Boolean = email.CheckDKIMSignature()
</pre>
<p>You can <a href="http://www.lesnikowski.com/mail/">download Mail.dll .NET email component here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/sign-emails-with-dkim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The handshake failed due to an unexpected packet format</title>
		<link>http://www.lesnikowski.com/blog/index.php/the-handshake-failed-due-to-an-unexpected-packet-format/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-handshake-failed-due-to-an-unexpected-packet-format</link>
		<comments>http://www.lesnikowski.com/blog/index.php/the-handshake-failed-due-to-an-unexpected-packet-format/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 16:59:37 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[POP3]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1009</guid>
		<description><![CDATA[Most likely your server requires implicit SSL. So first try to connect without SSL:

// C#

client.Connect(&#34;imap.example.com&#34;);


' VB.NET

client.Connect(&#34;imap.example.com&#34;);

Then, before logging-in, start implicit SSL negotiation. The command name differs for different protocols:
In case of IMAP:

// C#

client.StartTLS();


' VB.NET

client.StartTLS()

In case of POP3:

// C#

client.STLS();


' VB.NET

client.STLS()

In case of SMTP:

// C#

client.StartTLS();


' VB.NET

client.StartTLS()

Now, your connection is secured. 
Remember that you can ignore SSL certificate [...]]]></description>
			<content:encoded><![CDATA[<p>Most likely your server requires <strong>implicit </strong>SSL. So first try to connect without SSL:</p>
<pre class="brush: csharp;">
// C#

client.Connect(&quot;imap.example.com&quot;);
</pre>
<pre class="brush: vb;">
' VB.NET

client.Connect(&quot;imap.example.com&quot;);
</pre>
<p>Then, before logging-in, <strong>start implicit SSL negotiation</strong>. The command name differs for different protocols:</p>
<p>In case of <strong>IMAP</strong>:</p>
<pre class="brush: csharp;">
// C#

client.StartTLS();
</pre>
<pre class="brush: vb;">
' VB.NET

client.StartTLS()
</pre>
<p>In case of <strong>POP3</strong>:</p>
<pre class="brush: csharp;">
// C#

client.STLS();
</pre>
<pre class="brush: vb;">
' VB.NET

client.STLS()
</pre>
<p>In case of <strong>SMTP</strong>:</p>
<pre class="brush: csharp;">
// C#

client.StartTLS();
</pre>
<pre class="brush: vb;">
' VB.NET

client.StartTLS()
</pre>
<p>Now,<strong> your connection is secured</strong>. </p>
<p>Remember that you can ignore<strong> SSL certificate errors</strong> using <em>ServerCertificateValidate </em>event:</p>
<pre class="brush: csharp;">
// C#

client.ServerCertificateValidate +=
    (sender, e) =&gt; { e.IsValid = true; };
</pre>
<pre class="brush: vb;">
' VB.NET

client.ServerCertificateValidate += Function(sender, e) Do
	e.IsValid = True
End Function
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/the-handshake-failed-due-to-an-unexpected-packet-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download parts of email message</title>
		<link>http://www.lesnikowski.com/blog/index.php/download-parts-of-email-message/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=download-parts-of-email-message</link>
		<comments>http://www.lesnikowski.com/blog/index.php/download-parts-of-email-message/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 16:26:35 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=984</guid>
		<description><![CDATA[Some times you know you&#8217;ll receive large emails, but you only need to access some parts without downloading entire messages .
Mail.dll .NET IMAP client allows you to download only needed parts of the specified message.
First you need to get the structure of the message.
There are two methods for that: GetBodyStructureByUID and GetBodyStructure.
BodyStructure contains information about [...]]]></description>
			<content:encoded><![CDATA[<p>Some times you know you&#8217;ll receive large emails, but <strong>you only need to access some parts without downloading entire messages</strong> .</p>
<p><a href="http://www.lesnikowski.com/mail/">Mail.dll .NET IMAP client</a> allows you to download only needed parts of the specified message.</p>
<p>First you need to get the <strong>structure </strong>of the message.<br />
There are two methods for that: GetBodyStructureByUID and GetBodyStructure.</p>
<p><strong>BodyStructure </strong>contains information about plain text, html, and all attachments of the message. It does not contain any data though.</p>
<p>To <strong>download text</strong> parts of the email (like html or plain text) you can use: GetMimePartTextByUID or GetMimePartText.</p>
<p>To <strong>download attachments</strong> use: GetMimePartByUID or GetMimePart.</p>
<p>Here&#8217;s the full sample for this feature:</p>
<pre class="brush: csharp;">
// C#

using(Imap imap = new Imap())
{
	imap.Connect(&quot;imap.server.com&quot;);
	imap.Login(&quot;user&quot;, &quot;password&quot;);

	imap.SelectInbox();
	List&lt;long&gt; uidList = imap.SearchFlag(Flag.Unseen);
	foreach (long uid in uidList)
	{
		// Get the structure of the email
		BodyStructure structure = imap.GetBodyStructureByUID(uid);

		// Download only text and html parts
		string text = imap.GetMimePartTextByUID(uid, structure.Text);
		string html = imap.GetMimePartTextByUID(uid, structure.Html);

		Console.WriteLine(text);
		Console.WriteLine(html);

		// Show all attachments' filenames
		foreach(MimeStructure attachment in structure.Attachments)
		{
			Console.WriteLine(attachment.FileName);
			// You can also download entire attachment
			byte[] bytes = imap.GetMimePartByUID(uid, attachment);
		}
	}
	imap.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET

Using imap As New Imap()
	imap.Connect(&quot;imap.server.com&quot;)
	imap.Login(&quot;user&quot;, &quot;password&quot;)

	imap.SelectInbox()
	Dim uidList As List(Of Long) = imap.SearchFlag(Flag.Unseen)
	For Each uid As Long In uidList
		' Get the structure of the email
		Dim struct As BodyStructure = imap.GetBodyStructureByUID(uid)

		' Download only text and html parts
		Dim text As String = imap.GetMimePartTextByUID(
			uid, struct.Text)
		Dim html As String = imap.GetMimePartTextByUID(
			uid, struct.Html)

		Console.WriteLine(text)
		Console.WriteLine(html)

		' Show all attachments' filenames
		For Each attachment As MimeStructure In struct.Attachments
			Console.WriteLine(attachment.FileName)
			' You can also download entire attachment
			Dim bytes As Byte() = imap.GetMimePartByUID(
				uid, attachment)
		Next
	Next
	imap.Close(True)
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/download-parts-of-email-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Peek message on IMAP server</title>
		<link>http://www.lesnikowski.com/blog/index.php/peek-message-on-imap-server/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=peek-message-on-imap-server</link>
		<comments>http://www.lesnikowski.com/blog/index.php/peek-message-on-imap-server/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 15:00:42 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=978</guid>
		<description><![CDATA[When you access messages stored on IMAP  server, it automatically adds \Seen flag to the messages you have downloaded.
If you don&#8217;t want this behavior, there are two things you can do.
First is to use Examine method instead of Select:

// C#

using(Imap imap = new Imap())
{
    imap.Connect(&#34;imap.server.com&#34;);
    imap.Login(&#34;user&#34;, &#34;password&#34;);

  [...]]]></description>
			<content:encoded><![CDATA[<p>When you access messages stored on <strong>IMAP </strong> server, it <strong>automatically adds \Seen flag</strong> to the messages you have downloaded.</p>
<p>If you don&#8217;t want this behavior, there are two things you can do.</p>
<p>First is to use <strong>Examine </strong>method instead of Select:</p>
<pre class="brush: csharp;">
// C#

using(Imap imap = new Imap())
{
    imap.Connect(&quot;imap.server.com&quot;);
    imap.Login(&quot;user&quot;, &quot;password&quot;);

    imap.ExamineInbox(); // -or- imap.Examine(&quot;Inbox&quot;);

    // ...

    imap.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET

Using imap As New Imap
    imap.Connect(&quot;imap.server.com&quot;)
    imap.Login(&quot;user&quot;, &quot;password&quot;)

    imap.SelectInbox()

    imap.ExamineInbox() ' -or- imap.Examine(&quot;Inbox&quot;)

    ' ...

    imap.Close(True)
End Using
</pre>
<p>Examine puts mailbox (also called folder) into read-only state, so no \Seen flag is added.<br />
The drawback is that you can not delete a message.</p>
<p>Second approach is to use one of the <strong>Peek</strong> methods on the IMAP client:</p>
<pre class="brush: csharp;">
// C#

using(Imap imap = new Imap())
{
    imap.Connect(&quot;imap.server.com&quot;);
    imap.Login(&quot;user&quot;, &quot;password&quot;);

    imap.SelectInbox();
    List&lt;long&gt; uidList = imap.SearchFlag(Flag.Unseen);
    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.PeekMessageByUID(uid));
        Console.WriteLine(email.Subject);
    }
    imap.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET

Using imap As New Imap
    imap.Connect(&quot;imap.server.com&quot;)
    imap.Login(&quot;user&quot;, &quot;password&quot;)

    imap.SelectInbox()
    Dim uidList As List(Of Long) = imap.SearchFlag(Flag.Unseen)

    For Each uid As Long In uidList
        Dim email As IMail = New MailBuilder() _
            .CreateFromEml(imap.PeekMessageByUID(uid))
        Console.WriteLine(email.Subject)
    Next
    imap.Close(True)
End Using
</pre>
<p>There are <strong>Peek </strong>methods for downloading headers and even parts of the email message.</p>
<p>You can download <a href="http://www.lesnikowski.com/mail/">Mail.dll IMAP client here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/peek-message-on-imap-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Free Yahoo! Mail via IMAP</title>
		<link>http://www.lesnikowski.com/blog/index.php/free-yahoo-mail-via-imap/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=free-yahoo-mail-via-imap</link>
		<comments>http://www.lesnikowski.com/blog/index.php/free-yahoo-mail-via-imap/#comments</comments>
		<pubDate>Sun, 30 May 2010 09:59:33 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IDLE]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=911</guid>
		<description><![CDATA[It is possible to get direct Yahoo! IMAP access.
Yahoo! operates IMAP servers (imap.mail.yahoo.com in particular), which are globally accessible. 
However they require a specific, but non-standard IMAP command to be sent before login is done. The command is: “ID (&#8220;GUID&#8221; &#8220;1&#8243;)” 

// C#
imap.SendCommand(@&#34;ID (&#34;&#34;GUID&#34;&#34; &#34;&#34;1&#34;&#34;)&#34;);


' VB
imap.SendCommand(&#34;ID (&#34;&#34;GUID&#34;&#34; &#34;&#34;1&#34;&#34;)&#34;)

There is also an IMAP server running at [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2010/05/yahoo.gif" alt="" title="yahoo" width="142" height="38" class="alignleft size-full wp-image-917" />It is possible to get direct Yahoo! IMAP access.<br />
Yahoo! operates IMAP servers (imap.mail.yahoo.com in particular), which are globally accessible. </p>
<p>However <strong>they require a specific, but non-standard IMAP command to be sent before login</strong> is done. The command is: “ID (&#8220;GUID&#8221; &#8220;1&#8243;)” </p>
<pre class="brush: csharp;">
// C#
imap.SendCommand(@&quot;ID (&quot;&quot;GUID&quot;&quot; &quot;&quot;1&quot;&quot;)&quot;);
</pre>
<pre class="brush: vb;">
' VB
imap.SendCommand(&quot;ID (&quot;&quot;GUID&quot;&quot; &quot;&quot;1&quot;&quot;)&quot;)
</pre>
<p>There is also an IMAP server running at imap-ssl.mail.yahoo.com; it uses <strong>SSL</strong> on the standard port 993.</p>
<p>Here&#8217;s the full <strong>C#</strong> version of the code:</p>
<pre class="brush: csharp;">
using (Imap imap = new Imap())
{
    imap.Connect(&quot;imap.mail.yahoo.com&quot;);
    imap.SendCommand(@&quot;ID (&quot;&quot;GUID&quot;&quot; &quot;&quot;1&quot;&quot;)&quot;);

	imap.Login(&quot;user&quot;, &quot;password&quot;);

	imap.SelectInbox();
	List&lt;long&gt; uidList = imap.Search(Expression.All());
	foreach (long uid in uidList)
	{
		IMail email = new MailBuilder()
    			.CreateFromEml(imap.GetMessageByUID(uid));
		Console.WriteLine(email.Subject);
	}
	imap.Close(true);
}
</pre>
<p>and <strong>VB.NET</strong> version:</p>
<pre class="brush: vb;">
Using imap As New Imap()
	imap.Connect(&quot;imap.mail.yahoo.com&quot;)
	imap.SendCommand(&quot;ID (&quot;&quot;GUID&quot;&quot; &quot;&quot;1&quot;&quot;)&quot;)

	imap.Login(&quot;user&quot;, &quot;password&quot;)

	imap.SelectInbox()
	Dim uidList As List(Of Long) = imap.Search(Expression.All())
	For Each uid As Long In uidList
		Dim email As IMail = New MailBuilder() _
			.CreateFromEml(imap.GetMessageByUID(uid))
		Console.WriteLine(email.Subject)
	Next
	imap.Close(True)
End Using
</pre>
<p>Differences:<br />
- non-standard command ID command is required before any other command.<br />
- Examine explicitly requires CLOSE command (Imap.CloseCurrentFolder), otherwise subsequent SELECT (Imap.Select) has no effect and mailbox is still in read-only state<br />
- IDLE is not implemented.<br />
- SELECT for not existing folder does not create new folder.</p>
<p>You can download the latest version of <a href="http://www.lesnikowski.com/mail/">Mail.dll .NET IMAP client here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/free-yahoo-mail-via-imap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Imap IDLE</title>
		<link>http://www.lesnikowski.com/blog/index.php/imap-idle/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=imap-idle</link>
		<comments>http://www.lesnikowski.com/blog/index.php/imap-idle/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 05:22:42 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IDLE]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=831</guid>
		<description><![CDATA[IDLE  is an IMAP feature described in RFC 2177 that allows a client to indicate to the server that it is ready to accept real-time notifications.
IMAP4 servers that support IDLE will include this programming string in the result of their CAPABILITY command. 
You can use Capability method to check server&#8217;s capability list

// C# code

using [...]]]></description>
			<content:encoded><![CDATA[<p><strong>IDLE </strong> is an IMAP feature described in RFC 2177 that allows a client to indicate to the server that it is ready to accept <strong>real-time notifications</strong>.</p>
<p>IMAP4 servers that support IDLE will include this programming string in the result of their CAPABILITY command. </p>
<p>You can use <em>Capability </em>method to check server&#8217;s capability list</p>
<pre class="brush: csharp;">
// C# code

using (Imap client = new Imap())
{
	client.ConnectSSL(&quot;imap.server.com&quot;);
	client.Capability().ForEach(Console.WriteLine);
	client.Close();
}
</pre>
<pre class="brush: vb;">
' VB.NET code

Using client As New Imap()
	client.ConnectSSL(&quot;imap.server.com&quot;)
	client.Capability().ForEach(Console.WriteLine)
	client.Close()
End Using
</pre>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2010/04/capabilities.png" alt="" title="capabilities" width="288" height="154" class="aligncenter size-full wp-image-833" /></p>
<p><a href="http://www.lesnikowski.com/mail/">Mail.dll IMAP client</a> supports IDLE command.</p>
<p>There are two important methods:</p>
<ul>
<li><em>Idle()</em> &#8211; starts accepting real-time notifications. The method hangs until a notification is received.</li>
<li><em>StopIdle()</em> &#8211; stops accepting real-time notifications.</li>
</ul>
<pre class="brush: csharp;">
// C# code

using (Imap client = new Imap())
{
    client.ConnectSSL(&quot;imap.server.com&quot;);
    client.Login(&quot;user@server.com&quot;, &quot;password&quot;);

    FolderStatus folderStatus = client.SelectInbox();
    Console.WriteLine(&quot;Total message count: {0}&quot;,
        folderStatus.MessageCount);

    while(true)
    {
        FolderStatus currentStatus = client.Idle();
        Console.WriteLine(&quot;Total message count: {0}&quot;,
                currentStatus.MessageCount);
        foreach(long uid in client.SearchFlag(Flag.Unseen))
        {
            IMail email = new MailBuilder().CreateFromEml(
                client.GetHeadersByUID(uid));
            Console.WriteLine(email.Subject);
        }
    }
    client.Close();
}
</pre>
<pre class="brush: vb;">
' VB.NET code

Using client As New Imap()
	client.ConnectSSL(&quot;imap.server.com&quot;)
	client.Login(&quot;user@server.com&quot;, &quot;password&quot;)

	Dim folderStatus As FolderStatus = client.SelectInbox()
	Console.WriteLine(&quot;Total message count: {0}&quot;,_
		folderStatus.MessageCount)

	While True
		Dim currentStatus As FolderStatus = client.Idle()
		Console.WriteLine(&quot;Total message count: {0}&quot;,_
			currentStatus.MessageCount)
		For Each uid As Long In client.SearchFlag(Flag.Unseen)
			Dim email As IMail = New MailBuilder()_
 				.CreateFromEml(client.GetHeadersByUID(uid))
			Console.WriteLine(email.Subject)
		Next
	End While
	client.Close()
End Using
</pre>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2010/04/idle.png" alt="" title="idle" width="300" height="143" class="aligncenter size-full wp-image-842" /></p>
<p>Now lets handle stop gracefully:</p>
<pre class="brush: csharp;">
// C# code

using (Imap client = new Imap())
{
    client.ConnectSSL(&quot;imap.server.com&quot;);
    client.Login(&quot;user@server.com&quot;, &quot;password&quot;);

    FolderStatus folderStatus = client.SelectInbox();
    Console.WriteLine(&quot;Total message count: {0}&quot;,
        currentStatus.MessageCount);

    bool stop = false;
    // We start a new thread to handle user input, &lt;enter&gt; = stop idle
    new Thread(() =&gt;
	{
		Console.ReadLine();
		client.StopIdle();
		stop = true;
	}).Start();

    while(stop == false)
    {
        FolderStatus currentStatus = client.Idle();
        if (stop == true)
            break;

        Console.WriteLine(&quot;Total message count: {0}&quot;,
            currentStatus.MessageCount);

        foreach(long uid in client.SearchFlag(Flag.Unseen))
        {
            IMail email = new MailBuilder().CreateFromEml(
                client.GetHeadersByUID(uid));
            Console.WriteLine(email.Subject);
        }
    }
    client.Close();
}
</pre>
<pre class="brush: vb;">
' VB.NET code

Using client As New Imap()
	client.ConnectSSL(&quot;imap.server.com&quot;)
	client.Login(&quot;user@server.com&quot;, &quot;password&quot;)

	Dim folderStatus As FolderStatus = client.SelectInbox()
	Console.WriteLine(&quot;Total message count: {0}&quot;,_
		currentStatus.MessageCount)

	Dim [stop] As Boolean = False
	' We start a new thread to handle user input, &lt;enter&gt; = stop idle
	New Thread(Function() Do
		Console.ReadLine()
		client.StopIdle()
		[stop] = True
	End Function).Start()

	While [stop] = False
		Dim currentStatus As FolderStatus = client.Idle()
		If [stop] = True Then
			Exit While
		End If

		Console.WriteLine(&quot;Total message count: {0}&quot;,_
			currentStatus.MessageCount)

		For Each uid As Long In client.SearchFlag(Flag.Unseen)
			Dim email As IMail = New MailBuilder()_
				.CreateFromEml(client.GetHeadersByUID(uid))
			Console.WriteLine(email.Subject)
		Next
	End While
	client.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/imap-idle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending email with embedded image</title>
		<link>http://www.lesnikowski.com/blog/index.php/sending-email-with-embedded-image/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-email-with-embedded-image</link>
		<comments>http://www.lesnikowski.com/blog/index.php/sending-email-with-embedded-image/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 17:00:55 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=381</guid>
		<description><![CDATA[We&#8217;ll use Mail.dll email client.

We need to create an email message
Use src=&#8221;cid:imageID&#8221; as image source in HTML
Add the image to Visuals collection using AddVisual method
Apply image id by setting ContentId
And finally send the message


// Use builder class to create an email
MailBuilder builder = new MailBuilder();

// Set From, To
builder.From.Add(new MailBox(&#34;alice@mail.com&#34;, &#34;Alice&#34;));
builder.To.Add(new MailBox(&#34;bob@mail.com&#34;, &#34;Bob&#34;));
builder.Subject = &#34;Test&#34;;

// Set [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ll use <a href="http://www.lesnikowski.com/mail/">Mail.dll email client</a>.</p>
<ol>
<li>We need to create an email message</li>
<li>Use <em>src=&#8221;<strong>cid</strong>:imageID&#8221;</em> as image source in HTML</li>
<li>Add the image to Visuals collection using <em>AddVisual</em> method</li>
<li>Apply image id by setting <em>ContentId</em></li>
<li>And finally send the message</li>
</ol>
<pre class="brush: csharp;">
// Use builder class to create an email
MailBuilder builder = new MailBuilder();

// Set From, To
builder.From.Add(new MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;));
builder.To.Add(new MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;));
builder.Subject = &quot;Test&quot;;

// Set HTML content (Notice the src=&quot;cid:...&quot; attribute)
builder.SetHtmlData(@&quot;&lt;html&gt;&lt;body&gt;&lt;img src=&quot;&quot;cid:image1&quot;&quot; /&gt;&lt;/body&gt;&lt;/html&gt;&quot;);

// SetHtmlData automatically extracts plaint text from html so,
// unless you want to specify plain text explicitly, you don't need to use this method:
builder.SetTextData(&quot;This is text version of th message.&quot;);

// Add image and set its Content-Id
MimeData visual = builder.AddVisual(@&quot;c:\image.jpg&quot;);
visual.ContentType = new ContentType(MimeType.Image, MimeSubtype.Jpeg);
visual.ContentId = &quot;image1&quot;;

IMail email = builder.Create();

// Send the message
using (Smtp smtp = new Smtp())
{
    smtp.Connect(&quot;mail.host.com&quot;);
    smtp.Ehlo(HeloType.EhloHelo, &quot;yourname&quot;);
    smtp.Login(&quot;user&quot;, &quot;password&quot;);
    smtp.SendMessage(email);
    smtp.Close(false);
}
</pre>
<p>And of course the VB.NET version of the same code:</p>
<pre class="brush: vb;">
' Use builder class to create an email
Dim builder As New MailBuilder()

' Set From, To
builder.From.Add(New MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;))
builder.To.Add(New MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;))
builder.Subject = &quot;Test&quot;

' Set HTML content (Notice the src=&quot;cid:...&quot; attribute)
builder.SetHtmlData(&quot;&lt;html&gt;&lt;body&gt;&lt;img src=&quot;&quot;cid:image1&quot;&quot; /&gt;&lt;/body&gt;&lt;/html&gt;&quot;)

' SetHtmlData automatically extracts plaint text from html so,
' unless you want to specify plain text explicitly, you don't need to use this method:
builder.SetTextData(&quot;This is text version of th message.&quot;)

' Add image and set its Content-Id
Dim visual As MimeData = builder.AddVisual(&quot;c:\image.jpg&quot;)
visual.ContentType = New ContentType(MimeType.Image, MimeSubtype.Jpeg)
visual.ContentId = &quot;image1&quot;

Dim email As IMail = builder.Create()

' Send the message
Using smtp As New Smtp()
	smtp.Connect(&quot;mail.host.com&quot;)
	smtp.Ehlo(HeloType.EhloHelo, &quot;yourname&quot;)
	smtp.Login(&quot;user&quot;, &quot;password&quot;)
	smtp.SendMessage(email)
	smtp.Close(False)
End Using
</pre>
<p>Same code using fluent interface:</p>
<pre class="brush: csharp;">
Mail.Html(@&quot;&lt;html&gt;&lt;body&gt;&lt;img src=&quot;&quot;cid:image1&quot;&quot; /&gt;&lt;/body&gt;&lt;/html&gt;&quot;)
        .Text(&quot;This is text version of th message.&quot;)
        .From(new MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;))
        .To(new MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;))
        .Subject(&quot;Test&quot;)
        .AddVisual(@&quot;c:\image.jpg&quot;)
        .SetContentId(&quot;image1&quot;)
        .SetContentType(
                new ContentType(MimeType.Image, MimeSubtype.Jpeg))
        .UsingNewSmtp()
        .WithCredentials(&quot;lesnikowski&quot;,&quot;password&quot;)
        .Server(&quot;mail.host.com&quot;)
        .Send();
</pre>
<p>And of course the VB.NET version using fluent interface:</p>
<pre class="brush: vb;">
Mail.Html(&quot;&lt;html&gt;&lt;body&gt;&lt;img src=&quot;&quot;cid:image1&quot;&quot; /&gt;&lt;/body&gt;&lt;/html&gt;&quot;) _
	.Text(&quot;This is text version of th message.&quot;) _
	.From(New MailBox(&quot;alice@mail.com&quot;, &quot;Alice&quot;)) _
	.To(New MailBox(&quot;bob@mail.com&quot;, &quot;Bob&quot;)) _
	.Subject(&quot;Test&quot;).AddVisual(&quot;c:\image.jpg&quot;) _
	.SetContentId(&quot;image1&quot;) _
	.SetContentType( _
                New ContentType(MimeType.Image, MimeSubtype.Jpeg)) _
	.UsingNewSmtp() _
	.WithCredentials(&quot;lesnikowski&quot;, &quot;password&quot;) _
	.Server(&quot;mail.host.com&quot;) _
	.Send()
</pre>
<p>You can download <a href="http://www.lesnikowski.com/mail/">Mail.dll email client here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/sending-email-with-embedded-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
