<?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>Blog &#124; Limilabs &#187; Gmail</title>
	<atom:link href="http://www.limilabs.com/blog/tag/gmail/feed" rel="self" type="application/rss+xml" />
	<link>http://www.limilabs.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 21 May 2012 09:49:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Get Google contacts</title>
		<link>http://www.limilabs.com/blog/get-google-contacts?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=get-google-contacts</link>
		<comments>http://www.limilabs.com/blog/get-google-contacts#comments</comments>
		<pubDate>Fri, 13 Apr 2012 14:30:44 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[OAuth]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=2636</guid>
		<description><![CDATA[Although neither POP3 nor IMAP protocol allows retrieving the list of users contacts, it is possible to use Google API for that. As long as you are using OAuth to access Gmail, Mail.dll email component allows you to easy download Gmail contacts of a particular user. // C# GmailOAuth oauth = new GmailOAuth(_consumerKey, _consumerSecret); List&#60;GoogleScope&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Although neither POP3 nor IMAP protocol allows retrieving the list of users contacts, it is possible to use Google API for that.</p>
<p>As long as you are using <a href="http://www.limilabs.com/blog/oauth-with-gmail">OAuth to access Gmail</a>, Mail.dll <a href="http://www.limilabs.com/mail">email component </a>allows you to easy download Gmail contacts of a particular user.</p>
<pre class="brush: csharp;">
// C#

GmailOAuth oauth = new GmailOAuth(_consumerKey, _consumerSecret);

List&lt;GoogleScope&gt; scopes = new List&lt;GoogleScope&gt;
    {
        GoogleScope.EmailAddressScope,
        GoogleScope.ContactsScope
    };

string authUrl = oauth.GetAuthorizationUrl(&quot;http://localhost:64119/&quot;, scopes);

// ASP.NET client:
// Save oauth in permanent storage:
// Cache[oauth.RequestToken.Token] = oauth;

// Windows client:
Process.Start(url);

// ASP.NET client:
// Response.Redirect(url);

// Windows client with url:
string rawReturnUrl = Console.ReadLine();
ReturnUrl returnUrl = new ReturnUrl(rawReturnUrl);
oauth.GetAccessToken(returnUrl.OAuthVerifier);

// Windows client with verification code (oob):
// string oauthVerifier = HttpUtility.UrlDecode(Console.ReadLine());
// oauth.GetAccessToken(oauthVerifier);

// ASP.NET client:
// ReturnUrl returnUrl = new ReturnUrl(Request.RawUrl);
// Retrieve oauth from permanent storage:
// GmailOAuth oauth = Cache[returnUrl.OAuthToken]
// oauth.GetAccessToken(returnUrl.OAuthVerifier);

GoogleApi google = new GoogleApi(oauth.ConsumerToken, oauth.AccessToken);

XmlDocument contacts = google.GetContacts();

XmlNamespaceManager nsmgr = new XmlNamespaceManager(contacts.NameTable);
nsmgr.AddNamespace(&quot;gd&quot;, &quot;http://schemas.google.com/g/2005&quot;);
nsmgr.AddNamespace(&quot;a&quot;, &quot;http://www.w3.org/2005/Atom&quot;);

foreach (XmlNode contact in contacts.GetElementsByTagName(&quot;entry&quot;))
{
    XmlNode title = contact.SelectSingleNode(&quot;a:title&quot;, nsmgr);
    XmlNode email = contact.SelectSingleNode(&quot;gd:email&quot;, nsmgr);

    Console.WriteLine(&quot;{0}: {1}&quot;,
        title.InnerText,
        email.Attributes[&quot;address&quot;].Value);
}

oauth.RevokeToken(oauth.AccessToken.Token);
</pre>
<pre class="brush: vb;">
' VB.NET

Dim oauth As New GmailOAuth(_consumerKey, _consumerSecret)

Dim scopes As New List(Of GoogleScope)() With { _
	GoogleScope.EmailAddressScope, _
	GoogleScope.ContactsScope _
}
Dim authUrl As String = oauth.GetAuthorizationUrl(&quot;http://localhost:64119/&quot;, scopes)

' ASP.NET client:
' Save oauth in permanent storage:
' Cache[oauth.RequestToken.Token] = oauth;

' Windows client:
Process.Start(url)

' ASP.NET client:
' Response.Redirect(url)

' Windows client with url:
Dim rawReturnUrl As String = Console.ReadLine()
Dim returnUrl As New ReturnUrl(rawReturnUrl)
oauth.GetAccessToken(returnUrl.OAuthVerifier)

' Windows client with verification code (oob):
' Dim oauthVerifier As String = HttpUtility.UrlDecode(Console.ReadLine())
' oauth.GetAccessToken(oauthVerifier)

' ASP.NET client:
' Dim returnUrl As New ReturnUrl(Request.RawUrl)
' Retrive oauth from permanent storage:
' Dim oauth As GmailOAuth = Cache(returnUrl.OAuthToken)
' oauth.GetAccessToken(returnUrl.OAuthVerifier)

Dim google As New GoogleApi(oauth.ConsumerToken, oauth.AccessToken)
Dim contacts As XmlDocument = google.GetContacts()

Dim nsmgr As New XmlNamespaceManager(contacts.NameTable)
nsmgr.AddNamespace(&quot;gd&quot;, &quot;http://schemas.google.com/g/2005&quot;)
nsmgr.AddNamespace(&quot;a&quot;, &quot;http://www.w3.org/2005/Atom&quot;)

For Each contact As XmlNode In contacts.GetElementsByTagName(&quot;entry&quot;)
	Dim title As XmlNode = contact.SelectSingleNode(&quot;a:title&quot;, nsmgr)
	Dim email As XmlNode = contact.SelectSingleNode(&quot;gd:email&quot;, nsmgr)
	Console.WriteLine(&quot;{0}: {1}&quot;, _
            title.InnerText, _
            email.Attributes(&quot;address&quot;).Value)
Next

oauth.RevokeToken(oauth.AccessToken.Token)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/get-google-contacts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Label message with Gmail system label (e.g. Starred)</title>
		<link>http://www.limilabs.com/blog/label-message-with-gmail-system-label-starred?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=label-message-with-gmail-system-label-starred</link>
		<comments>http://www.limilabs.com/blog/label-message-with-gmail-system-label-starred#comments</comments>
		<pubDate>Sat, 31 Mar 2012 07:08:40 +0000</pubDate>
		<dc:creator>Limilabs support</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.limilabs.com/blog/?p=2565</guid>
		<description><![CDATA[If you want to use user-defined label please read label message with user defined label. There are two ways of labeling message with Gmail system label (e.g. Starred) Imap.GmailLabelMessageByUID method GmailLabelMessageByUID method uses Gmail&#8217;s X-GM-LABELS extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @&#8221;\Starred&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to use user-defined label please read <a href="http://www.limilabs.com/blog/label-message-with-gmail-label">label message with user defined label</a>.</p>
<p>There are two ways of labeling message with Gmail system label (e.g. Starred)</p>
<h2>Imap.GmailLabelMessageByUID method</h2>
<p><em>GmailLabelMessageByUID </em>method uses Gmail&#8217;s <strong>X-GM-LABELS</strong> extension to the IMAP protocol. You need to provide a folder flag name for it to work correctly e.g. @&#8221;\Starred&#8221;.</p>
<p>You can use FolderFlag class static properties to get common flags:<br />
<em>FolderFlag.XImportant</em>, <em>FolderFlag.XSpam</em>, <em>FolderFlag.XStarred</em>.</p>
<pre class="brush: csharp;">
// C#

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

    imap.SelectInbox();
    long last = imap.GetAll().Last();

    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name);

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

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 last As Long = imap.GetAll().Last()

    imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name)

    imap.Close()
End Using
</pre>
<h2>Imap.CopyByUID method</h2>
<p>The second method basis on the fact that <strong>Gmail treats labels as regular IMAP folders</strong>.<br />
You just need to know correct folder name and copy the message to this folder.</p>
<p>You can use <em>CommonFolders </em>class to get common folders:</p>
<pre class="brush: csharp;">
// C#

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

    List&lt;FolderInfo&gt; folders = imap.GetFolders();

    imap.SelectInbox();
    long last = imap.GetAll().Last();

    imap.CopyByUID(last, new CommonFolders(folders).Starred);

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

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

    Dim folders As List(Of FolderInfo) = imap.GetFolders()

    imap.SelectInbox()
    Dim last As Long = imap.GetAll().Last()

    imap.CopyByUID(last, New CommonFolders(folders).Starred)

    imap.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/label-message-with-gmail-system-label-starred/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List all Gmail labels</title>
		<link>http://www.limilabs.com/blog/list-all-gmail-labels?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=list-all-gmail-labels</link>
		<comments>http://www.limilabs.com/blog/list-all-gmail-labels#comments</comments>
		<pubDate>Fri, 30 Mar 2012 10:32:39 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[X-GM-LABELS]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=2566</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. // C# using (Imap imap [...]]]></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.limilabs.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>
<pre class="brush: csharp;">
// C#

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

    List&lt;FolderInfo&gt; folders = imap.GetFolders();
    List&lt;FolderInfo&gt; system = folders.FindAll(x =&gt; x.Name.StartsWith(&quot;[Gmail]&quot;));
    List&lt;FolderInfo&gt; user = folders.FindAll(x =&gt; !x.Name.StartsWith(&quot;[Gmail]&quot;));

    Console.WriteLine(&quot;System labels:&quot;);
    system.ForEach(x =&gt; Console.WriteLine(x.Name));
    Console.WriteLine();
    Console.WriteLine(&quot;User labels:&quot;);
    user.ForEach(x =&gt; Console.WriteLine(x.Name));

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

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

    Dim folders As List(Of FolderInfo) = imap.GetFolders()
    Dim system As List(Of FolderInfo) =
        folders.FindAll(Function(x) x.Name.StartsWith(&quot;[Gmail]&quot;))
    Dim user As List(Of FolderInfo) =
        folders.FindAll(Function(x) Not x.Name.StartsWith(&quot;[Gmail]&quot;))

    Console.WriteLine(&quot;System labels:&quot;)
    system.ForEach(Function(x) Console.WriteLine(x.Name))
    Console.WriteLine()
    Console.WriteLine(&quot;User labels:&quot;)
    user.ForEach(Function(x) Console.WriteLine(x.Name))

    imap.Close()
End Using
</pre>
<p>Here is the output:</p>
<p><code><br />
System labels:<br />
[Gmail]<br />
[Gmail]/All Mail<br />
[Gmail]/Drafts<br />
[Gmail]/Sent Mail<br />
[Gmail]/Spam<br />
[Gmail]/Starred<br />
[Gmail]/Trash<br />
</code></p>
<p><code><br />
User labels:<br />
my label<br />
my label/nested<br />
my second label<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/list-all-gmail-labels/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download unseen emails from Gmail using IMAP video</title>
		<link>http://www.limilabs.com/blog/download-unseen-emails-from-gmail-using-imap-video?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=download-unseen-emails-from-gmail-using-imap-video</link>
		<comments>http://www.limilabs.com/blog/download-unseen-emails-from-gmail-using-imap-video#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:34:31 +0000</pubDate>
		<dc:creator>Limilabs support</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[video]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=2425</guid>
		<description><![CDATA[In this video you&#8217;ll learn how to: Create new application that references Mail.dll IMAP component. Configure Gmail to allow IMAP access. Connect and login to Gmail using SSL secured channel. Search and download unseen emails. Parse downloaded email messages. and finally access most common email properties like subject, sender, attachments. Enjoy:]]></description>
			<content:encoded><![CDATA[<p>In this video you&#8217;ll learn how to:</p>
<ul>
<li>Create new application that references Mail.dll <a href="http://www.limilabs.com/mail">IMAP component</a>.</li>
<li>Configure Gmail to allow IMAP access. </li>
<li>Connect and login to Gmail using SSL secured channel.</li>
<li>Search and download unseen emails.</li>
<li>Parse downloaded email messages.</li>
<li>and finally access most common email properties like subject, sender, attachments.</li>
</ul>
<p>Enjoy:</p>
<p><object type="application/x-shockwave-flash" style="width:640px; height:505px;" data="http://www.youtube.com/v/SxFuw1OBKlc?rel=0&amp;showsearch=0&amp;version=3&amp;modestbranding=1"><param name="movie" value="http://www.youtube.com/v/I16OVFIKQzM?rel=0&amp;showsearch=0&amp;version=3&amp;modestbranding=1" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/download-unseen-emails-from-gmail-using-imap-video/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archive email in Gmail</title>
		<link>http://www.limilabs.com/blog/archive-email-in-gmail?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=archive-email-in-gmail</link>
		<comments>http://www.limilabs.com/blog/archive-email-in-gmail#comments</comments>
		<pubDate>Fri, 06 Jan 2012 10:54:01 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>

		<guid isPermaLink="false">http://www.limilabs.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.limilabs.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.limilabs.com/blog/archive-email-in-gmail/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable POP3 in Gmail</title>
		<link>http://www.limilabs.com/blog/enable-pop3-in-gmail?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enable-pop3-in-gmail</link>
		<comments>http://www.limilabs.com/blog/enable-pop3-in-gmail#comments</comments>
		<pubDate>Fri, 06 Jan 2012 10:33:17 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://www.limilabs.com/blog/?p=2231</guid>
		<description><![CDATA[To enable POP3 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 POP for all mail or Enable POP for mail that arrives from now on. Now you are able to connect to your Gmail account with Mail.dll POP3 library. [...]]]></description>
			<content:encoded><![CDATA[<p>To enable POP3 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 POP for all mail</strong> or <strong>Enable POP for mail that arrives from now on</strong>.</li>
<li>Now you are able to connect to your Gmail account with <a href="http://www.limilabs.com/mail">Mail.dll POP3 library</a>.</li>
</ol>
<p>Remember that Gmail only allows <strong>secure SSL connections</strong> so you need to use <strong>ConnectSSL </strong>method.</p>
<p>Now you can  <a href="http://www.limilabs.com/blog/download-emails-gmail-pop3">download emails from Gmail using POP3 protocol</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/enable-pop3-in-gmail/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Enable IMAP in Gmail</title>
		<link>http://www.limilabs.com/blog/enable-imap-in-gmail?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enable-imap-in-gmail</link>
		<comments>http://www.limilabs.com/blog/enable-imap-in-gmail#comments</comments>
		<pubDate>Fri, 06 Jan 2012 10:26:31 +0000</pubDate>
		<dc:creator>Limilabs support</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[IMAP]]></category>

		<guid isPermaLink="false">http://www.limilabs.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 you 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.limilabs.com/mail">Mail.dll IMAP library</a>.</li>
</ol>
<p>Remember that Gmail only allows <strong>secure SSL connections</strong> so you need to use <strong>ConnectSSL </strong>method.</p>
<p>Now you can <a href="http://www.limilabs.com/blog/download-emails-from-gmail">download emails from Gmail using IMAP protocol</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/enable-imap-in-gmail/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OAuth with Gmail</title>
		<link>http://www.limilabs.com/blog/oauth-with-gmail?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oauth-with-gmail</link>
		<comments>http://www.limilabs.com/blog/oauth-with-gmail#comments</comments>
		<pubDate>Fri, 21 Oct 2011 17:27:39 +0000</pubDate>
		<dc:creator>Limilabs support</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.limilabs.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 with Mail.dll IMAP component. The key advantage of this method is that it allows an application to access user [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.limilabs.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 with <a href="http://www.limilabs.com/mail">Mail.dll IMAP component</a>. 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" rel="nofollow">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" rel="nofollow">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 Mail.dll and appropriate namespaces.</p>
<pre class="brush: csharp;">
// C#

using Limilabs.Client.IMAP;
using Limilabs.Client.Authentication;
using Limilabs.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;);

// ASP.NET client:
// Save oauth in permanent storage:
// Cache[oauth.RequestToken.Token] = oauth;

// Windows client:
Process.Start(url);

// ASP.NET client:
// Response.Redirect(url);

// Windows client with url:
string rawReturnUrl = Console.ReadLine();
ReturnUrl returnUrl = new ReturnUrl(rawReturnUrl);
oauth.GetAccessToken(returnUrl.OAuthVerifier);

// Windows client with verification code (oob):
// string oauthVerifier = HttpUtility.UrlDecode(Console.ReadLine());
// oauth.GetAccessToken(oauthVerifier);

// ASP.NET client:
// ReturnUrl returnUrl = new ReturnUrl(Request.RawUrl);
// Retrieve oauth from permanent storage:
// GmailOAuth oauth = Cache[returnUrl.OAuthToken]
// oauth.GetAccessToken(returnUrl.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.limilabs.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 (oob):</p>
<p><img src="http://www.limilabs.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.limilabs.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 Limilabs.Client.IMAP
Imports Limilabs.Client.Authentication
Imports Limilabs.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;)

' ASP.NET client:
' Save oauth in permanent storage:
' Cache[oauth.RequestToken.Token] = oauth;

' Windows client:
Process.Start(url)

' ASP.NET client:
' Response.Redirect(url)

' Windows client with url:
Dim rawReturnUrl As String = Console.ReadLine()
Dim returnUrl As New ReturnUrl(rawReturnUrl)
oauth.GetAccessToken(returnUrl.OAuthVerifier)

' Windows client with verification code (oob):
' Dim oauthVerifier As String = HttpUtility.UrlDecode(Console.ReadLine())
' oauth.GetAccessToken(oauthVerifier)

' ASP.NET client:
' Dim returnUrl As New ReturnUrl(Request.RawUrl)
' Retrive oauth from permanent storage:
' Dim oauth As GmailOAuth = Cache(returnUrl.OAuthToken)
' oauth.GetAccessToken(returnUrl.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.limilabs.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.limilabs.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.limilabs.com/blog/2-legged-oauth-with-gmail#comments</comments>
		<pubDate>Fri, 21 Oct 2011 16:31:02 +0000</pubDate>
		<dc:creator>Limilabs support</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.limilabs.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.limilabs.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" rel="nofollow">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" rel="nofollow">http://code.google.com/apis/gmail/oauth/protocol.html</a></p>
<p>Remember to add reference to Mail.dll and appropriate namespaces.</p>
<pre class="brush: csharp;">
// C#

using Limilabs.Client.IMAP;
using Limilabs.Client.Authentication;
using Limilabs.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(&quot;imap.gmail.com&quot;);

    string oauthImapKey = oauth.GetXOAuthKeyForImap(email);

    client.LoginOAUTH(oauthImapKey);

    //...

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

Imports Limilabs.Client.IMAP
Imports Limilabs.Client.Authentication
Imports Limilabs.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(&quot;imap.gmail.com&quot;)

	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.limilabs.com/blog/wp-content/uploads/2011/01/2LeggedOAuth1.png"><img src="http://www.limilabs.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.limilabs.com/blog/wp-content/uploads/2011/01/2LeggedOAuth2.png"><img src="http://www.limilabs.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.limilabs.com/blog/2-legged-oauth-with-gmail/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create Gmail url-ID via IMAP</title>
		<link>http://www.limilabs.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.limilabs.com/blog/create-gmail-url-id-via-imap#comments</comments>
		<pubDate>Tue, 30 Aug 2011 09:10:07 +0000</pubDate>
		<dc:creator>Limilabs support</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.limilabs.com/blog/?p=1942</guid>
		<description><![CDATA[This is Gmail link that points to certain conversation (entire thread): 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 points to the Gmail conversation // C# [...]]]></description>
			<content:encoded><![CDATA[<p>This is Gmail link that points to certain conversation (entire thread):</p>
<p><code>https://mail.google.com/mail/u/0/#inbox/13216515baefe747</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 points 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 'All Mail' folder
    CommonFolders common = new CommonFolders(client.GetFolders());
    client.Select(common.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 'All Mail' folder
	Dim common As New CommonFolders(client.GetFolders())
	client.Select(common.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.limilabs.com/blog/search-gmail-thread-id">search by X-GM-THRID</a> and all other <a href="http://www.limilabs.com/blog/gmail-extensions-in-mail-dll"> Gmail IMAP extensions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.limilabs.com/blog/create-gmail-url-id-via-imap/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

