<?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; IMAP</title>
	<atom:link href="http://www.lesnikowski.com/blog/tag/imap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lesnikowski.com/blog</link>
	<description>EMAIL IMAP POP3 SMTP FTP FTPS barcode components blog</description>
	<lastBuildDate>Fri, 03 Feb 2012 19:20:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Archive email in Gmail</title>
		<link>http://www.lesnikowski.com/blog/archive-email-in-gmail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=archive-email-in-gmail</link>
		<comments>http://www.lesnikowski.com/blog/archive-email-in-gmail/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 10:54:01 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2240</guid>
		<description><![CDATA[First remember to enable IMAP in Gmail. You need to use DeleteMessageByUID method. Messages will be still available in All Mail folder. // C# using(Imap imap = new Imap()) { imap.ConnectSSL(&#34;imap.gmail.com&#34;); imap.Login(&#34;user&#34;, &#34;password&#34;); // Find all emails we want to delete imap.SelectInbox(); List&#60;long&#62; uids = imap.Search( Expression.Subject(&#34;email to archive&#34;)); imap.DeleteMessageByUID(uids); imap.Close(); } ' VB.NET Using [...]]]></description>
			<content:encoded><![CDATA[<p>First remember to <a href="http://www.lesnikowski.com/blog/enable-imap-in-gmail/">enable IMAP in Gmail</a>.</p>
<p>You need to use DeleteMessageByUID method. Messages will be still available in All Mail folder.</p>
<pre class="brush: csharp;">
// C#

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

	// Find all emails we want to delete
	imap.SelectInbox();
	List&lt;long&gt; uids = imap.Search(
		Expression.Subject(&quot;email to archive&quot;));

	imap.DeleteMessageByUID(uids);

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

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

	' Find all emails we want to delete
	imap.SelectInbox()
	Dim uids As List(Of Long) = imap.Search(_
		Expression.Subject(&quot;email to archive&quot;))

	imap.DeleteMessageByUID(uids)

	imap.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/archive-email-in-gmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable IMAP in Gmail</title>
		<link>http://www.lesnikowski.com/blog/enable-imap-in-gmail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enable-imap-in-gmail</link>
		<comments>http://www.lesnikowski.com/blog/enable-imap-in-gmail/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 10:26:31 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2224</guid>
		<description><![CDATA[To enable IMAP in Gmail: Sign in to Gmail. Click the gear icon in the upper-right and select Mail settings . Click Forwarding and POP/IMAP. Select Enable IMAP. Now you are able to connect to your Gmail account with Mail.dll IMAP library. Remember that Gmail only allows secure SSL connections so we need to use [...]]]></description>
			<content:encoded><![CDATA[<p>To enable IMAP in Gmail:</p>
<ol>
<li>Sign in to Gmail.</li>
<li>Click the <strong>gear icon</strong> in the upper-right and select <strong>Mail settings </strong>.</li>
<li>Click <strong>Forwarding and POP/IMAP</strong>.</li>
<li>Select <strong>Enable IMAP</strong>.</li>
<li>Now you are able to connect to your Gmail account with <a href="http://www.lesnikowski.com/mail/">Mail.dll IMAP library</a>.</li>
</ol>
<p>Remember that Gmail only allows <strong>secure SSL connections</strong> so we need to use <strong>ConnectSSL </strong>method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/enable-imap-in-gmail/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OAuth with Gmail</title>
		<link>http://www.lesnikowski.com/blog/oauth-with-gmail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oauth-with-gmail</link>
		<comments>http://www.lesnikowski.com/blog/oauth-with-gmail/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 17:27:39 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[XOAuth]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2030</guid>
		<description><![CDATA[OAuth is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications. In this post I&#8217;ll show how to access Gmail account using 3-legged OAuth authentication method. The key advantage of this method is that it allows an application to access user email without knowing user&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail.png" alt="" title="gmail" width="131" height="61" class="alignleft size-full wp-image-271" /></p>
<p><strong>OAuth </strong> is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.</p>
<p>In this post<strong> I&#8217;ll show how to access Gmail</strong> account using 3-legged OAuth authentication method. The key advantage of this method is that it allows an application to access user email <strong>without knowing user&#8217;s password.</strong></p>
<p>You can read more on OAuth authentication with Google accounts here:<br />
<a href="http://code.google.com/apis/accounts/docs/OAuth_ref.html">http://code.google.com/apis/accounts/docs/OAuth_ref.html</a></p>
<p>Gmail IMAP and SMTP using OAuth:<br />
<a href="http://code.google.com/apis/gmail/oauth/protocol.html">http://code.google.com/apis/gmail/oauth/protocol.html</a></p>
<p>If your application/website is not registered, you should use following key and secret:<br />
consumer key: &#8220;anonymous&#8221;<br />
consumer secret: &#8220;anonymous&#8221;</p>
<p>Remember to add reference to Maill.dll and appropriate namespaces.</p>
<pre class="brush: csharp;">
// C#

using Lesnikowski.Client.IMAP;
using Lesnikowski.Client.Authentication;
using Lesnikowski.Client.Authentication.Google;

const string userEmailAccount = &quot;pat@gmail.com&quot;;
const string consumerKey = &quot;anonymous&quot;;
const string consumerSecret = &quot;anonymous&quot;;

GmailOAuth oauth = new GmailOAuth(
    consumerKey, consumerSecret);

string url = oauth.GetAuthorizationUrl(&quot;http://localhost:64119/&quot;);

Process.Start(url);
// You can use Response.Redirect(url) in ASP.NET

string oauthVerifier = HttpUtility.UrlDecode(Console.ReadLine());
// You can use Request[&quot;oauth_verifier&quot;].ToString() in ASP.NET

oauth.GetAccessToken(oauthVerifier);

using (Imap client = new Imap())
{
    client.ConnectSSL(&quot;imap.gmail.com&quot;);
    string oauthImapKey = oauth.GetXOAuthKeyForImap();
    client.LoginOAUTH(oauthImapKey);

    // Now you can access user's emails
    //...

    client.Close();
    oauth.RevokeToken(oauthImapKey);
}
</pre>
<p>1.<br />
<strong>GmailOAuth.GetAuthorizationUrl</strong> method returns url you should redirect your user to so he can authorize access.<br />
As you can see Mail.dll is asking for access to user&#8217;s email information and Gmail access:</p>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/10/GmailOAuth_Authorize.png" alt="" title="GmailOAuth_Authorize" width="536" height="537" class="aligncenter size-full wp-image-2043" /></p>
<p>2.<br />
If you<strong> don&#8217;t specify callback</strong> parameter, user will have to <strong>manually </strong>copy&#038;paste the token to your application:</p>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/10/GmailOAuth_OOBAuthorize.png" alt="" title="GmailOAuth_OOBAuthorize" width="536" height="350" class="aligncenter size-full wp-image-2044" /></p>
<p>In case of a <strong>web project</strong>, you can specify<strong> a web address on your website</strong>. oauth_verifier will be included as the redirection url parameter.</p>
<p>After the redirection, your website/application needs to<strong> read oauth_verifier query parameter</strong>:</p>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/10/GmailOAuth_Redirect.png" alt="" title="GmailOAuth_Redirect" width="536" height="133" class="aligncenter size-full wp-image-2045" /></p>
<p>3.<br />
<strong>GmailOAuth.GetAccessToken</strong> method authorizes the token.</p>
<p>4.<br />
<strong>GmailOAuth.GetXOAuthKeyForImap</strong> method <strong>uses Google API to get the email address</strong> of the user, and generates XOAuth key for IMAP protocol (you can use GetXOAuthKeyForSmtp for SMTP).</p>
<p>5.<br />
<strong>GmailOAuth.RevokeToken</strong> method <strong>revokes XOAuth key</strong>, so no further access can be made with it.</p>
<p>&#8230;and finally VB.NET version of the code:</p>
<pre class="brush: vb;">
' VB.NET

Imports Lesnikowski.Client.IMAP
Imports Lesnikowski.Client.Authentication
Imports Lesnikowski.Client.Authentication.Google

Const userEmailAccount As String = &quot;pat@gmail.com&quot;
Const consumerKey As String = &quot;anonymous&quot;
Const consumerSecret As String = &quot;anonymous&quot;

Dim oauth As New GmailOAuth(consumerKey, consumerSecret)

Dim url As String = oauth.GetAuthorizationUrl(&quot;http://localhost:64119/&quot;)

Process.Start(url)
' You can use Response.Redirect(url) in ASP.NET

Dim oauthVerifier As String = HttpUtility.UrlDecode(Console.ReadLine())
' You can use Request[&quot;oauth_verifier&quot;].ToString() in ASP.NET

oauth.GetAccessToken(oauthVerifier)

Using client As New Imap()
	client.ConnectSSL(&quot;imap.gmail.com&quot;)
	Dim oauthImapKey As String = oauth.GetXOAuthKeyForImap()
	client.LoginOAUTH(oauthImapKey)

	' Now you can access user's emails
	'...

	client.Close()
	oauth.RevokeToken(oauthImapKey)
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/oauth-with-gmail/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>2-legged OAuth with Gmail</title>
		<link>http://www.lesnikowski.com/blog/2-legged-oauth-with-gmail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=2-legged-oauth-with-gmail</link>
		<comments>http://www.lesnikowski.com/blog/2-legged-oauth-with-gmail/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 16:31:02 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[XOAuth]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2031</guid>
		<description><![CDATA[OAuth is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications. In this post I&#8217;ll show how to access Gmail account using 2-legged OAuth authentication method. The basic idea is that domain administrator can use this method to access user email without knowing user&#8217;s password. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail.png" alt="" title="gmail" width="131" height="61" class="alignleft size-full wp-image-271" /></p>
<p><strong>OAuth </strong> is an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications.</p>
<p>In this post<strong> I&#8217;ll show how to access Gmail</strong> account using 2-legged OAuth authentication method. The basic idea is that domain administrator can use this method to access user email <strong>without knowing user&#8217;s password.</strong></p>
<p>You can read more on OAuth authentication with Google accounts here:<br />
<a href="http://code.google.com/apis/accounts/docs/OAuth_ref.html">http://code.google.com/apis/accounts/docs/OAuth_ref.html</a></p>
<p>Gmail IMAP and SMTP using OAuth:<br />
<a href="http://code.google.com/apis/gmail/oauth/protocol.html">http://code.google.com/apis/gmail/oauth/protocol.html</a></p>
<p>Remember to add reference to Maill.dll and appropriate namespaces.</p>
<pre class="brush: csharp;">
// C#

using Lesnikowski.Client.IMAP;
using Lesnikowski.Client.Authentication;
using Lesnikowski.Client.Authentication.Google;

const string consumerKey = &quot;example.com&quot;;
const string consumerSecret = &quot;secret&quot;;
const string email = &quot;pat@example.com&quot;;

Gmail2LeggedOAuth oauth = new Gmail2LeggedOAuth(
    consumerKey, consumerSecret);

using (Imap client = new Imap())
{
    client.ConnectSSL(TestConstants.GmailImapServer);

    string oauthImapKey = oauth.GetXOAuthKeyForImap(email);

    client.LoginOAUTH(oauthImapKey);

    //...

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

Imports Lesnikowski.Client.IMAP
Imports Lesnikowski.Client.Authentication
Imports Lesnikowski.Client.Authentication.Google

Const  consumerKey As String = &quot;example.com&quot;
Const  consumerSecret As String = &quot;secret&quot;
Const  email As String = &quot;pat@example.com&quot;

Dim oauth As New Gmail2LeggedOAuth(consumerKey, consumerSecret)

Using client As New Imap()
	client.ConnectSSL(TestConstants.GmailImapServer)

	Dim oauthImapKey As String = oauth.GetXOAuthKeyForImap(email)

	client.LoginOAUTH(oauthImapKey)

	'...

	client.Close()
End Using
</pre>
<p>Here are the google apps configuration screens:</p>
<p><a href="http://www.lesnikowski.com/blog/wp-content/uploads/2011/01/2LeggedOAuth1.png"><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/01/2LeggedOAuth1-300x233.png" alt="" title="2LeggedOAuth1" width="300" height="233" class="aligncenter size-medium wp-image-1937" /></a></p>
<p><a href="http://www.lesnikowski.com/blog/wp-content/uploads/2011/01/2LeggedOAuth2.png"><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/01/2LeggedOAuth2-300x233.png" alt="" title="2LeggedOAuth2" width="300" height="233" class="aligncenter size-medium wp-image-1938" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/2-legged-oauth-with-gmail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get supported authentication methods (IMAP, POP3, SMTP)</title>
		<link>http://www.lesnikowski.com/blog/get-supported-authentication-methods-imap-pop3-smtp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=get-supported-authentication-methods-imap-pop3-smtp</link>
		<comments>http://www.lesnikowski.com/blog/get-supported-authentication-methods-imap-pop3-smtp/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 15:13:53 +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=2000</guid>
		<description><![CDATA[You can use SupportedAuthenticationMethodsto retrieve all authentication methods supported by the server: // C# using (Imap client = new Imap()) { client.ConnectSSL(&#34;imap.example.org&#34;); client.UseBestLogin(&#34;user&#34;, &#34;password&#34;); Console.WriteLine(&#34;Supported methods:&#34;); foreach (var method in client.SupportedAuthenticationMethods()) { Console.WriteLine(method.Name); } Console.WriteLine(&#34;Supports CramMD5:&#34;); bool supportsCramMD5 = client.SupportedAuthenticationMethods() .Contains(ImapAuthenticationMethod.CramMD5); Console.WriteLine(supportsCramMD5); client.Close(); } ' VB.NET Using client As New Imap() client.ConnectSSL(&#34;imap.example.org&#34;) client.UseBestLogin(&#34;user&#34;, &#34;password&#34;) Console.WriteLine(&#34;Supported [...]]]></description>
			<content:encoded><![CDATA[<p>You can use <em>SupportedAuthenticationMethods</em>to retrieve all authentication methods supported by the server:</p>
<pre class="brush: csharp;">
// C#

using (Imap client = new Imap())
{
    client.ConnectSSL(&quot;imap.example.org&quot;);
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported methods:&quot;);

    foreach (var method in client.SupportedAuthenticationMethods())
    {
        Console.WriteLine(method.Name);
    }

    Console.WriteLine(&quot;Supports CramMD5:&quot;);

    bool supportsCramMD5 = client.SupportedAuthenticationMethods()
        .Contains(ImapAuthenticationMethod.CramMD5);

    Console.WriteLine(supportsCramMD5);

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

Using client As New Imap()
    client.ConnectSSL(&quot;imap.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported methods:&quot;)

    For Each method As ImapAuthenticationMethod In client.SupportedAuthenticationMethods()
	    Console.WriteLine(method.Name)
    Next

    Console.WriteLine(&quot;Supports CramMD5:&quot;)

    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _
        .Contains(ImapAuthenticationMethod.CramMD5)

    Console.WriteLine(supportsCramMD5)

    client.Close()
End Using
</pre>
<p>For example Gmail produces following output:</p>
<pre class="brush: plain;">
Supported method s:
IMAP4rev1
UNSELECT
IDLE
NAMESPACE
QUOTA
ID
XLIST
CHILDREN
X-GM-EXT-1
UIDPLUS
COMPRESS

Supports CramMD5:
False
</pre>
<p>We take great care for the API to look similar for all protocols (IMAP, POP3, SMTP).</p>
<p>Here&#8217;s the<strong> sample for POP3</strong>:</p>
<pre class="brush: csharp;">
// C#

using (Pop3 client = new Pop3())
{
    client.ConnectSSL(&quot;pop3.example.org&quot;);
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported methods:&quot;);

    foreach (var method in client.SupportedAuthenticationMethods())
    {
        Console.WriteLine(method.Name);
    }

    Console.WriteLine(&quot;Supports CramMD5:&quot;);

    bool supportsCramMD5 = client.SupportedAuthenticationMethods()
        .Contains(Pop3AuthenticationMethod.CramMD5);

    Console.WriteLine(supportsCramMD5);

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

Using client As New Pop3()
    client.ConnectSSL(&quot;pop3.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported methods:&quot;)

    For Each method As Pop3AuthenticationMethod In client.SupportedAuthenticationMethods()
	    Console.WriteLine(method.Name)
    Next

    Console.WriteLine(&quot;Supports CramMD5:&quot;)

    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _
        .Contains(Pop3AuthenticationMethod.CramMD5)

    Console.WriteLine(supportsCramMD5)

    client.Close()
End Using
</pre>
<p>Here&#8217;s the<strong> sample for SMTP</strong>:</p>
<pre class="brush: csharp;">
// C#

using (Smtpclient = new Smtp())
{
    client.Connect(&quot;smtp.example.org&quot;);
    client.UseBestLogin(&quot;smtp&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported methods:&quot;);

    foreach (var method in client.SupportedAuthenticationMethods())
    {
        Console.WriteLine(method.Name);
    }

    Console.WriteLine(&quot;Supports CramMD5:&quot;);

    bool supportsCramMD5 = client.SupportedAuthenticationMethods()
        .Contains(SmtpAuthenticationMethod.CramMD5);

    Console.WriteLine(supportsCramMD5);

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

Using client As New Smtp()
    client.Connect(&quot;smtp.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported methods:&quot;)

    For Each method As SmtpAuthenticationMethod In client.SupportedAuthenticationMethods()
	    Console.WriteLine(method.Name)
    Next

    Console.WriteLine(&quot;Supports CramMD5:&quot;)

    Dim supportsCramMD5 As Boolean = client.SupportedAuthenticationMethods() _
        .Contains(SmtpAuthenticationMethod.CramMD5)

    Console.WriteLine(supportsCramMD5)

    client.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/get-supported-authentication-methods-imap-pop3-smtp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get supported server extensions (IMAP, POP3, SMTP)</title>
		<link>http://www.lesnikowski.com/blog/get-supported-server-extensions-imap-pop3-smtp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=get-supported-server-extensions-imap-pop3-smtp</link>
		<comments>http://www.lesnikowski.com/blog/get-supported-server-extensions-imap-pop3-smtp/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 12:46:12 +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>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1992</guid>
		<description><![CDATA[You can use SupportedExtensionsmethod to retrieve all protocol extensions supported by the server: // C# using (Imap client = new Imap()) { client.ConnectSSL(&#34;imap.example.org&#34;); client.UseBestLogin(&#34;user&#34;, &#34;password&#34;); Console.WriteLine(&#34;Supported extensions:&#34;); foreach (ImapExtension extension in client.SupportedExtensions()) { Console.WriteLine(extension.Name); } Console.WriteLine(&#34;Supports IDLE:&#34;); bool supportsIdle = client.SupportedExtensions() .Contains(ImapExtension.Idle); Console.WriteLine(supportsIdle); client.Close(); } ' VB.NET Using client As New Imap() client.ConnectSSL(&#34;imap.example.org&#34;) client.UseBestLogin(&#34;user&#34;, &#34;password&#34;) [...]]]></description>
			<content:encoded><![CDATA[<p>You can use <em>SupportedExtensionsmethod </em>to retrieve all protocol extensions supported by the server:</p>
<pre class="brush: csharp;">
// C#

using (Imap client = new Imap())
{
    client.ConnectSSL(&quot;imap.example.org&quot;);
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported extensions:&quot;);

    foreach (ImapExtension extension in client.SupportedExtensions())
    {
        Console.WriteLine(extension.Name);
    }

    Console.WriteLine(&quot;Supports IDLE:&quot;);

    bool supportsIdle = client.SupportedExtensions()
        .Contains(ImapExtension.Idle);

    Console.WriteLine(supportsIdle);

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

Using client As New Imap()
    client.ConnectSSL(&quot;imap.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported extensions:&quot;)

    For Each extension As ImapExtension In client.SupportedExtensions()
	    Console.WriteLine(extension.Name)
    Next

    Console.WriteLine(&quot;Supports IDLE:&quot;)

    Dim supportsIdle As Boolean = client.SupportedExtensions() _
        .Contains(ImapExtension.Idle)

    Console.WriteLine(supportsIdle)

    client.Close()
End Using
</pre>
<p>For example Gmail produces following output:</p>
<pre class="brush: plain;">
Supported extensions:
IMAP4rev1
UNSELECT
IDLE
NAMESPACE
QUOTA
ID
XLIST
CHILDREN
X-GM-EXT-1
UIDPLUS
COMPRESS

Supports IDLE:
True
</pre>
<p>We take great care for the API to look similar for all protocols (IMAP, POP3, SMTP).</p>
<p>Here&#8217;s the<strong> sample for POP3</strong>:</p>
<pre class="brush: csharp;">
// C#

using (Pop3 client = new Pop3())
{
    client.ConnectSSL(&quot;pop3.example.org&quot;);
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported extensions:&quot;);

    foreach (Pop3Extension extension in client.SupportedExtensions())
    {
        Console.WriteLine(extension.Name);
    }

    Console.WriteLine(&quot;Supports TOP:&quot;);

    bool supportsTop= client.SupportedExtensions()
        .Contains(Pop3Extension.Top);

    Console.WriteLine(supportsTop);

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

Using client As New Pop3()
    client.ConnectSSL(&quot;pop3.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported extensions:&quot;)

    For Each extension As Pop3Extension In client.SupportedExtensions()
	    Console.WriteLine(extension.Name)
    Next

    Console.WriteLine(&quot;Supports TOP:&quot;)

    Dim supportsTop As Boolean = client.SupportedExtensions() _
        .Contains(Pop3Extension.Top)

    Console.WriteLine(supportsTop)

    client.Close()
End Using
</pre>
<p>Here&#8217;s the<strong> sample for SMTP</strong>:</p>
<pre class="brush: csharp;">
// C#

using (Smtpclient = new Smtp())
{
    client.Connect(&quot;smtp.example.org&quot;);
    client.UseBestLogin(&quot;smtp&quot;, &quot;password&quot;);

    Console.WriteLine(&quot;Supported extensions:&quot;);

    foreach (SmtpExtension  extension in client.SupportedExtensions())
    {
        Console.WriteLine(extension.Name);
    }

    Console.WriteLine(&quot;Supports STARTTLS:&quot;);

    bool supportsStartTLS = client.SupportedExtensions()
        .Contains(SmtpExtension.StartTLS);

    Console.WriteLine(supportsStartTLS);

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

Using client As New Smtp()
    client.Connect(&quot;smtp.example.org&quot;)
    client.UseBestLogin(&quot;user&quot;, &quot;password&quot;)

    Console.WriteLine(&quot;Supported extensions:&quot;)

    For Each extension As SmtpExtension In client.SupportedExtensions()
	    Console.WriteLine(extension.Name)
    Next

    Console.WriteLine(&quot;Supports STARTTLS:&quot;)

    Dim supportsStartTLS As Boolean = client.SupportedExtensions() _
        .Contains(SmtpExtension.StartTLS)

    Console.WriteLine(supportsStartTLS)

    client.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/get-supported-server-extensions-imap-pop3-smtp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove attachments from email</title>
		<link>http://www.lesnikowski.com/blog/remove-attachments-from-email/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=remove-attachments-from-email</link>
		<comments>http://www.lesnikowski.com/blog/remove-attachments-from-email/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 08:59:16 +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[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1986</guid>
		<description><![CDATA[First I want to make one thing clear, neither POP3 nor IMAP protocols does not provide any way to remove attachments from existing emails. This is because email stored on the server is immutable. With IMAP protocol you can copy it to different folder, you can apply some flags (SEEN) to it, but you can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>First I want to make one thing clear, neither <strong>POP3 nor IMAP protocols does not provide any way to remove attachments from existing emails</strong>.<br />
This is because email stored on the server is immutable.<br />
With IMAP protocol you can copy it to different folder, you can apply some flags (SEEN) to it, but you can&#8217;t change any part of the message.</p>
<p>The second important thing is that attachments are not stored separately from the message text and headers &#8211; they are embedded inside the email.</p>
<p>Nevertheless Mail.dll provides an easy way to create new email without the attachments from existing email message.</p>
<pre class="brush: csharp;">
// C# 

IMail original = new MailBuilder().CreateFromEml(eml);
IMail email = original.RemoveAttachments().Create();
</pre>
<pre class="brush: vb;">
' VB.NET

Dim original As IMail = New MailBuilder().CreateFromEml(eml)
Dim email As IMail = original.RemoveAttachments().Create()
</pre>
<p>RemoveAttachments method also has an <strong>overloaded version that allows to remove only visual</strong> (content-disposition: inline) or/and non-visual (content-disposition: attachment) attachments:</p>
<pre class="brush: csharp;">
// C# 

MailBuilder RemoveAttachments();

MailBuilder RemoveAttachments(
    bool removeVisuals,
    bool removeNonVisuals);
</pre>
<pre class="brush: vb;">
' VB.NET

Function RemoveAttachments() As MailBuilder

Function RemoveAttachments( _
    removeVisuals As Boolean, _
    removeNonVisuals As Boolean) As MailBuilder
</pre>
<p>The following example illustrates the full process of <strong>downloading </strong>email from IMAP server,<br />
creating new email, with the same information, but without attachments, and finally <strong>uploading </strong>it, and removing the original message:</p>
<pre class="brush: csharp;">
// C# 

using(Imap imap = new Imap())
{
    imap.ConnectSSL(&quot;imap.example.org&quot;);
    imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;);
    imap.SelectInbox();

    foreach (long uid in imap.GetAll())
    {
        string eml = imap.GetMessageByUID(uid);
        IMail original = new MailBuilder().CreateFromEml(eml);
        if (original.Attachments.Count &gt; 0)
        {
            IMail email = original.RemoveAttachments().Create();

            imap.UploadMessage(&quot;Inbox&quot;, email);

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

Using imap As New Imap()
   imap.ConnectSSL(&quot;imap.example.org&quot;)
   imap.UseBestLogin(&quot;user&quot;, &quot;password&quot;)
   imap.SelectInbox()

   For Each uid As Long In imap.GetAll()
      Dim eml As String = imap.GetMessageByUID(uid)
      Dim original As IMail = New MailBuilder().CreateFromEml(eml)
      If original.Attachments.Count &gt; 0 Then
         Dim email As IMail = original.RemoveAttachments().Create()

         imap.UploadMessage(&quot;Inbox&quot;, email)

         imap.DeleteMessageByUID(uid)
      End If
   Next
   imap.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/remove-attachments-from-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Gmail url-ID via IMAP</title>
		<link>http://www.lesnikowski.com/blog/create-gmail-url-id-via-imap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-gmail-url-id-via-imap</link>
		<comments>http://www.lesnikowski.com/blog/create-gmail-url-id-via-imap/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 09:10:07 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[X-GM-THRID]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1942</guid>
		<description><![CDATA[This is Gmail link that points to certain conversation: https://mail.google.com/mail/u/0/#inbox/13216515baefe747 &#8220;13216515baefe747&#8243; is the Gmail thread-ID in hex. Here&#8217;s the code that: Selects &#8220;All Mail&#8221; folder Gets the newest message UID Obtains Gmail thread ID for this message (X-GM-THRID) Converts it to hex Creates the url that point to the Gmail conversation // C# version using [...]]]></description>
			<content:encoded><![CDATA[<p>This is Gmail link that points to certain conversation:</p>
<p><code></p>
<p>https://mail.google.com/mail/u/0/#inbox/13216515baefe747</p>
<p></code></p>
<p>&#8220;13216515baefe747&#8243; is the Gmail thread-ID in hex.</p>
<p>Here&#8217;s the code that:</p>
<ol>
<li>Selects &#8220;All Mail&#8221; folder</li>
<li>Gets the newest message UID</li>
<li>Obtains Gmail thread ID for this message (X-GM-THRID)</li>
<li>Converts it to hex</li>
<li>Creates the url that point to the Gmail conversation</li>
</ol>
<pre class="brush: csharp;">
// C# version

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

    // select &quot;All Mail&quot; folder
    List&amp;lt;FolderInfo&amp;gt; allFolders = client.GetFolders();
    FolderInfo allMail = new CommonFolders(allFolders).AllMail;
    client.Select(allMail);

    // get IMAP uid of the newest message
    long lastUid = client.GetAll().Last();

    // get message info
    MessageInfo info = client.GetMessageInfoByUID(lastUid);

    // extract Gmail thread ID
    Int64 threadId = Int64.Parse(info.Envelope.GmailThreadId);
    string threadIdAsHex = threadId.ToString&quot;X&quot;);

    // create url
    string url = string.Format(
        &quot;https://mail.google.com/mail/u/0/#inbox/{0}&quot;,
        threadIdAsHex);

    Console.WriteLine(url);

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

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

	' select &quot;All Mail&quot; folder
	Dim allFolders As List(Of FolderInfo) = client.GetFolders()
	Dim allMail As FolderInfo = New CommonFolders(allFolders).AllMail
	client.[Select](allMail)

	' get IMAP uid of the newest message
	Dim lastUid As Long = client.GetAll().Last()

	' get message info
	Dim info As MessageInfo = client.GetMessageInfoByUID(lastUid)

	' extract Gmail thread ID
	Dim threadId As Int64 = Int64.Parse(info.Envelope.GmailThreadId)
	Dim threadIdAsHex As String = threadId.ToString(&quot;X&quot;)

	' create url
	Dim url As String = String.Format( _
		&quot;https://mail.google.com/mail/u/0/#inbox/{0}&quot;, _
		threadIdAsHex)

	Console.WriteLine(url)

	client.Close()
End Using
</pre>
<p>Here you can find some more information about how to <a href="http://www.lesnikowski.com/blog/search-gmail-thread-id/">search by X-GM-THRID</a> and all other <a href="http://www.lesnikowski.com/blog/gmail-extensions-in-mail-dll/"> Gmail IMAP extensions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/create-gmail-url-id-via-imap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gmail extensions in Mail.dll</title>
		<link>http://www.lesnikowski.com/blog/gmail-extensions-in-mail-dll/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gmail-extensions-in-mail-dll</link>
		<comments>http://www.lesnikowski.com/blog/gmail-extensions-in-mail-dll/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 13:05:11 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[X-GM-LABELS]]></category>
		<category><![CDATA[X-GM-MSGID]]></category>
		<category><![CDATA[X-GM-RAW]]></category>
		<category><![CDATA[X-GM-THRID]]></category>
		<category><![CDATA[XLIST]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1907</guid>
		<description><![CDATA[Here&#8217;s the list of Gmail IMAP protocol extensions implemented in Mail.dll: Extension of the LIST command: XLIST Extension of the SEARCH command: X-GM-RAW Access to the Gmail unique message ID: X-GM-MSGID Access to the Gmail thread ID: X-GM-THRID Access to Gmail labels: X-GM-LABELS You can read on how to use Mail.dll with Gmail in the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail.png" alt="" title="gmail" width="131" height="61" class="alignleft size-full wp-image-271" /><br />
Here&#8217;s the list of <strong>Gmail</strong> <strong>IMAP </strong>protocol extensions implemented in Mail.dll:</p>
<ul>
<li>Extension of the LIST command: <strong>XLIST</strong></li>
<li>Extension of the SEARCH command:<strong> X-GM-RAW</strong></li>
<li>Access to the Gmail unique message ID: <strong>X-GM-MSGID</strong></li>
<li>Access to the Gmail thread ID: <strong>X-GM-THRID</strong></li>
<li>Access to Gmail labels: <strong>X-GM-LABELS</strong></li>
</ul>
<p>You can read on how to use Mail.dll with Gmail in the following articles:</p>
<ul>
<li><a href="http://www.lesnikowski.com/blog/get-gmail-thread-id/">Get Gmail thread id</a></li>
<li><a href="http://www.lesnikowski.com/blog/search-gmail-thread-id/">Search Gmail thread id</a></li>
<li><a href="http://www.lesnikowski.com/blog/get-gmail-message-id/">Get Gmail message id</a></li>
<li><a href="http://www.lesnikowski.com/blog/search-gmail-message-id/">Search Gmail message id</a></li>
<li><a href="http://www.lesnikowski.com/blog/get-gmail-labels-for-specified-messages/">Get Gmail labels for specified messages</a></li>
<li><a href="http://www.lesnikowski.com/blog/label-message-with-gmail-label/">Label message with Gmail label</a></li>
<li><a href=" http://www.lesnikowski.com/blog/search-gmail-label/">Search Gmail label</a></li>
<li><a href="http://www.lesnikowski.com/blog/localized-gmail-imap-folders">Localized Gmail IMAP Folders </a></li>
<li><a href="http://www.lesnikowski.com/blog/search-gmail-using-gmails-search-syntax/">Search Gmail using Gmail&#8217;s search syntax</a></li>
<li><a href="http://www.lesnikowski.com/blog/create-gmail-url-id-via-imap/">Create Gmail url-ID via IMAP</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/gmail-extensions-in-mail-dll/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Search Gmail label</title>
		<link>http://www.lesnikowski.com/blog/search-gmail-label/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=search-gmail-label</link>
		<comments>http://www.lesnikowski.com/blog/search-gmail-label/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 13:02:27 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[X-GM-LABELS]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1896</guid>
		<description><![CDATA[Gmail treats labels as folders for the purposes of IMAP. As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders. System labels, which are labels created by Gmail, are reserved and prefixed by &#8220;[Gmail]&#8221; or &#8220;[GoogleMail]&#8221; in the list of labels. Use the XLIST command to [...]]]></description>
			<content:encoded><![CDATA[<p>Gmail treats labels as folders for the purposes of IMAP. </p>
<p>As such, labels can be modified using the standard IMAP commands, <a href="http://www.lesnikowski.com/blog/folder-management-using-imap-create-delete-rename">CreateFolder, RenameFolder, and DeleteFolder</a>, that act on folders.</p>
<p>System labels, which are labels created by Gmail, are reserved and prefixed by &#8220;[Gmail]&#8221; or &#8220;[GoogleMail]&#8221; in the list of labels. </p>
<p>Use the <a href="http://www.lesnikowski.com/blog/list-all-folders-using-imap">XLIST command to get the entire list of labels for a mailbox</a>.</p>
<p>The labels for a given message may be retrieved by using the X-GM-LABELS attribute with the FETCH command. </p>
<p>It is also possible to use the X-GM-LABELS attribute to return the UIDs for all messages with a given label, using the SEARCH command.</p>
<pre class="brush: csharp;">
// C# version

using (Imap imap = new Imap())
{
    imap.ConnectSSL(&quot;imap.gmail.com&quot;);
    imap.Login(&quot;pat@gmail.com&quot;, &quot;password&quot;);

    imap.SelectInbox();

    List&lt;long&gt; uids = imap.Search().Where(
        Expression.GmailLabel(&quot;MyLabel&quot;));

    foreach (MessageInfo info in imap.GetMessageInfoByUID(uids))
    {
        Console.WriteLine(&quot;{0} - {1}&quot;,
            info.Envelope.GmailThreadId,
            info.Envelope.Subject);
    }

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

Using imap As New Imap()
	imap.ConnectSSL(&quot;imap.gmail.com&quot;)
	imap.Login(&quot;pat@gmail.com&quot;, &quot;password&quot;)

	imap.SelectInbox()

	Dim uids As List(Of Long) = imap.Search().Where(Expression.GmailLabel(&quot;MyLabel&quot;))

	For Each info As MessageInfo In imap.GetMessageInfoByUID(uids)
            Console.WriteLine(&quot;{0} - {1}&quot;,  _
                info.Envelope.GmailThreadId,  _
                info.Envelope.Subject)
	Next

	imap.Close()
End Using
</pre>
<p>You can learn more about this Gmail IMAP extension here:<br />
<a href="http://code.google.com/apis/gmail/imap/#x-gm-labels">http://code.google.com/apis/gmail/imap/#x-gm-labels</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/search-gmail-label/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

