<?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/tag/vb-net/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>Sun, 05 Feb 2012 14:10:23 +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>Send iCalendar meeting requests for different timezone</title>
		<link>http://www.lesnikowski.com/blog/send-icalendar-meeting-requests-for-different-timezone/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=send-icalendar-meeting-requests-for-different-timezone</link>
		<comments>http://www.lesnikowski.com/blog/send-icalendar-meeting-requests-for-different-timezone/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 14:18:57 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[iCalendar]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=1842</guid>
		<description><![CDATA[Usually you define time of an event in relation to UTC time zone. If you need to define event on 9:00 o&#8217;clock in Alaska you simply need to subtract 9 hours from event time to get the event time in UTC (18:00:00). 18 &#8211; 9 = 9. It all works great in December (Alaska is [...]]]></description>
			<content:encoded><![CDATA[<p>Usually you define time of an event in relation to UTC time zone.</p>
<p>If you need to define event on 9:00 o&#8217;clock in Alaska you simply need<br />
to subtract 9 hours from event time to get the event time in UTC<br />
(18:00:00). 18 &#8211; 9 = 9.</p>
<p>It all works great in December (Alaska is UTC-9), but in May, daylight<br />
saving time is in effect in Alaska (Alaska is UTC-8 then).</p>
<p>If the event is recurring, in May, event is going to be held on 10:00<br />
Alaska time (18 &#8211; 8 = 10). Which is most likely not what you want.</p>
<p>As the time zones in different parts of world change way to often to reflect these changes in Mail.dll,<br />
you&#8217;ll need to specify the time zone when creating new event (including the daylight savings time).</p>
<p>Here&#8217;s the sample:</p>
<pre class="brush: csharp;">
// C#
using Fluent = Lesnikowski.Mail.Fluent;
using Lesnikowski.Client;
using Lesnikowski.Mail;
using Lesnikowski.Mail.Appointments;

Appointment appointment = new Appointment();

// Create time zone
VTimeZone alaska = appointment.AddTimeZone();
alaska.TimeZoneId = &quot;America/Anchorage&quot;;

// Define standard time offset
var standardRecurring = new RecurringRule();
standardRecurring.Frequency = Frequency.Yearly;
standardRecurring.ByDay.Add(Weekday.Sunday);
standardRecurring.ByMonths.Add(11);

var standard = new StandardOffset
{
    Name = &quot;AKST&quot;,
    Start = new DateTime(1970, 11, 01, 02, 00, 00),
    OffsetFrom = TimeSpan.FromHours(-8),
    OffsetTo = TimeSpan.FromHours(-9),
    RecurringRule = standardRecurring
};

// Define daylight time offset
var daylightRecurring = new RecurringRule();
daylightRecurring.Frequency = Frequency.Yearly;
daylightRecurring.ByDay.Add(new Weekday(2, Weekday.Sunday));
daylightRecurring.ByMonths.Add(3);

var daylight = new DaylightOffset
{
    Name = &quot;AKDT&quot;,
    Start = new DateTime(1970, 03, 08, 02, 00, 00),
    OffsetFrom = TimeSpan.FromHours(-9),
    OffsetTo = TimeSpan.FromHours(-8),
    RecurringRule = daylightRecurring
};

alaska.Standard.Add(standard);
alaska.Daylight.Add(daylight);

// Define event
Event e = appointment.AddEvent();
e.Start = new DateTime(2007, 08, 17, 12, 00, 00);
e.End = new DateTime(2007, 08, 17, 12, 30, 00);
e.Summary = &quot;At noon in Alaska&quot;;
e.InTimeZone(alaska);

e.SetOrganizer(new Person(&quot;Alice&quot;, &quot;alice@example.org&quot;));

e.AddParticipant(new Participant(
    &quot;Bob&quot;, &quot;bob@example.org&quot;, ParticipationRole.Required, true));
e.AddParticipant(new Participant(
    &quot;Tom&quot;, &quot;tom@example.org&quot;, ParticipationRole.Optional, true));
e.AddParticipant(new Participant(
    &quot;Alice&quot;, &quot;alice@example.org&quot;, ParticipationRole.Required, true));

Alarm alarm = e.AddAlarm();
alarm.BeforeStart(TimeSpan.FromMinutes(15));

IMail email = Fluent.Mail
    .Text(&quot;Status meeting at noon in Alaska.&quot;)
    .Subject(&quot;Status meeting&quot;)
    .From(&quot;alice@example.org&quot;)
    .To(&quot;bob@example.org&quot;)
    .To(&quot;tom@example.org&quot;)
    .AddAppointment(appointment)
    .Create();

using (Smtp smtp = new Smtp())
{
    smtp.Connect(&quot;smtp.example.org&quot;); // or ConnectSSL
    smtp.Login(&quot;user&quot;, &quot;password&quot;);
    smtp.SendMessage(email);
    smtp.Close();
}
</pre>
<pre class="brush: vb;">
' VB.NET
Imports Fluent = Lesnikowski.Mail.Fluent
Imports Lesnikowski.Client
Imports Lesnikowski.Mail
Imports Lesnikowski.Mail.Appointments

Dim appointment As New Appointment()

' Create time zone
Dim alaska As VTimeZone = appointment.AddTimeZone()
alaska.TimeZoneId = &quot;America/Anchorage&quot;

' Define standard time offset
Dim standardRecurring = New RecurringRule()
standardRecurring.Frequency = Frequency.Yearly
standardRecurring.ByDay.Add(Weekday.Sunday)
standardRecurring.ByMonths.Add(11)

Dim standard = New StandardOffset() With { _
	.Name = &quot;AKST&quot;, _
	.Start = New DateTime(1970, 11, 1, 2, 0, 0), _
	.OffsetFrom = TimeSpan.FromHours(-8), _
	.OffsetTo = TimeSpan.FromHours(-9), _
	.RecurringRule = standardRecurring _
}

' Define daylight time offset
Dim daylightRecurring = New RecurringRule()
daylightRecurring.Frequency = Frequency.Yearly
daylightRecurring.ByDay.Add(New Weekday(2, Weekday.Sunday))
daylightRecurring.ByMonths.Add(3)

Dim daylight = New DaylightOffset() With { _
	.Name = &quot;AKDT&quot;, _
	.Start = New DateTime(1970, 3, 8, 2, 0, 0), _
	.OffsetFrom = TimeSpan.FromHours(-9), _
	.OffsetTo = TimeSpan.FromHours(-8), _
	.RecurringRule = daylightRecurring _
}

alaska.Standard.Add(standard)
alaska.Daylight.Add(daylight)

' Define event
Dim e As [Event] = appointment.AddEvent()
e.Start = New DateTime(2007, 8, 17, 12, 0, 0)
e.[End] = New DateTime(2007, 8, 17, 12, 30, 0)
e.Summary = &quot;At noon in Alaska&quot;
e.InTimeZone(alaska)

e.SetOrganizer(New Person(&quot;Alice&quot;, &quot;alice@example.org&quot;))

e.AddParticipant(New Participant( _
	&quot;Bob&quot;, &quot;bob@example.org&quot;, ParticipationRole.Required, True))
e.AddParticipant(New Participant( _
	&quot;Tom&quot;, &quot;tom@example.org&quot;, ParticipationRole.[Optional], True))
e.AddParticipant(New Participant( _
	&quot;Alice&quot;, &quot;alice@example.org&quot;, ParticipationRole.Required, True))

Dim alarm As Alarm = e.AddAlarm()
alarm.BeforeStart(TimeSpan.FromMinutes(15))

Dim email As IMail = Fluent.Mail _
	.Text(&quot;Status meeting at noon in Alaska.&quot;) _
	.Subject(&quot;Status meeting&quot;) _
	.From(&quot;alice@example.org&quot;) _
	.[To](&quot;bob@example.org&quot;) _
	.[To](&quot;tom@example.org&quot;) _
	.AddAppointment(appointment) _
	.Create()

Using smtp As New Smtp()
	smtp.Connect(&quot;smtp.example.org&quot;) 	' or ConnectSSL
	smtp.Login(&quot;user&quot;, &quot;password&quot;)
	smtp.SendMessage(email)
	smtp.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/send-icalendar-meeting-requests-for-different-timezone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mail.dll .NET email spam filter</title>
		<link>http://www.lesnikowski.com/blog/mail-dll-net-email-spam-filter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mail-dll-net-email-spam-filter</link>
		<comments>http://www.lesnikowski.com/blog/mail-dll-net-email-spam-filter/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 10:49:29 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2075</guid>
		<description><![CDATA[Mail.dll .NET email component includes high accuracy anti-spam filter. It uses enhanced naive Bayesian classifier, specifically modified to handle email messages. Bayesian spam filters are a very powerful technique for dealing with spam. In our tests we achieved 99,6% accuracy with very low false positive spam detection rates (9 false positives in 54&#8217;972 emails tested [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lesnikowski.com/mail/">Mail.dll .NET email component</a> includes high accuracy <strong>anti-spam filter</strong>.</p>
<p>It uses enhanced naive Bayesian classifier, specifically modified to handle email messages. Bayesian spam filters are a very powerful technique for dealing with spam.</p>
<p>In our tests we achieved <strong>99,6% accuracy</strong> with very low false positive spam detection rates (9 false positives in 54&#8217;972 emails tested &#8211; that&#8217;s 0.016%).</p>
<h3>Training</h3>
<p>First in the learning phase, you need to teach the classifier to recognize spam and non-spam (ham) messages. You need to prepare 100-200 spam and ham messages. </p>
<p>I suggest using following folder structure:</p>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/10/Bayes_FolderStructure.png" alt="" title="Bayes_FolderStructure" width="480" height="149" class="aligncenter size-full wp-image-2076" /></p>
<p>&#8220;Learn&#8221; folder is used for training the filter. Both spam and ham folders should contain around 100-200 messages each (the more the better). <strong>The number of messages in spam and ham folders must be equal</strong>. You can find a spam archive on the bottom of the article.</p>
<p>Messages must be in eml format with correct line endings (rn or 13 10 hex).</p>
<p>Now we use <em>SpamFilterTeacher </em> class to teach <em>BayesianMailFilter</em>:</p>
<pre class="brush: csharp;">
// C#
using Lesnikowski.Mail.Tools.Spam;

BayesianMailFilter filter = new BayesianMailFilter();
SpamFilterTeacher teacher = new SpamFilterTeacher(filter);
teacher.TeachSpam(@&quot;c:bayeslearnspam&quot;);
teacher.TeachHam(@&quot;c:bayeslearnham&quot;);
</pre>
<h3>Testing</h3>
<p>&#8220;Test&#8221; folder is used for testing our filter:</p>
<pre class="brush: csharp;">
// C#

SpamTestResults r = teacher.Test(
    @&quot;c:bayestestspam&quot;,
    @&quot;c:bayestestham&quot;);

Console.WriteLine(r);
r.FalsePositives.ForEach(Console.WriteLine);
r.NotMarkedAsSpam.ForEach(Console.WriteLine);
</pre>
<p>The results should be similar to this:<br />
<code><br />
Accuracy=0.9949, False positives=9, Not marked as spam=271, Tests count=54972<br />
c:bayestestham�16874.eml<br />
...<br />
</code></p>
<p>When the filter is trained and the results are satisfactory, you can <strong>save it to disk</strong>:</p>
<pre class="brush: csharp;">
// C#

filter.Save(&quot;c:\20111022.mbayes&quot;);
</pre>
<h3>Using</h3>
<p>You can load the filter from disk and check individual messages:</p>
<pre class="brush: csharp;">
// C#

BayesianMailFilter filter = new BayesianMailFilter();
filter.Load(&quot;c:\20111022.mbayes&quot;);

// you can use Mail.dll to download mesage from POP3 or IMAP server:
string eml = ... 

IMail email = new MailBuilder().CreateFromEml(eml);

SpamResult result = filter.Examine(email);
Console.WriteLine(result.Probability);
Console.WriteLine(result.IsSpam);
</pre>
<p>If the filter incorrectly recognizes the message you can train it again:</p>
<pre class="brush: csharp;">
// C#

filter.LearnSpam(email);
// - or -
filter.LearnHam(email);

filter.Save(&quot;c:\20111022.mbayes&quot;);
</pre>
<h3>Spam archives</h3>
<p>For most recent spam you can check this great archive: <a href="http://www.untroubled.org/spam/" rel="no_follow">http://www.untroubled.org/spam/</a>.<br />
Unfortunately messages <strong>don&#8217;t have correct extension</strong> (*.eml) and <strong>line endings are incorrect</strong>.</p>
<p>You can download spam archive including 7874 spam messages from Oct 2011 here:<br />
<a href="http://www.lesnikowski.com/mail/spam/spam201110.zip">http://www.lesnikowski.com/mail/spam/spam201110.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/mail-dll-net-email-spam-filter/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>FTP Active vs Passive</title>
		<link>http://www.lesnikowski.com/blog/ftp-active-vs-passive/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ftp-active-vs-passive</link>
		<comments>http://www.lesnikowski.com/blog/ftp-active-vs-passive/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 10:05:23 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Ftp.dll]]></category>
		<category><![CDATA[FTPS]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2019</guid>
		<description><![CDATA[Ftp.dll .NET FTP component supports both Active and Passive mode FTP transfers. In Active mode client waits for incomming data connections, in Passive mode client establishes data connections. Passive mode is default. You can switch to Active mode using Mode property: // C# using (Ftp client = new Ftp()) { client.Mode = FtpMode.Active; client.Connect(&#34;ftp.example.com&#34;); client.Login(&#34;user&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Ftp.dll <a href="http://www.lesnikowski.com/ftp/">.NET FTP component</a> supports both Active and Passive mode FTP transfers.</p>
<p>In <strong>Active</strong> mode client waits for incomming data connections, in <strong>Passive</strong> mode client establishes data connections.</p>
<p>Passive mode is default. You can switch to Active mode using <strong>Mode</strong> property:</p>
<pre class="brush: csharp;">
// C#

using (Ftp client = new Ftp())
{
    client.Mode = FtpMode.Active;

    client.Connect(&quot;ftp.example.com&quot;);
    client.Login(&quot;user&quot;, &quot;password&quot;);

    // ...

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

Using client As New Ftp()
    client.Mode = FtpMode.Active

    client.Connect(&quot;ftp.example.com&quot;)
    client.Login(&quot;user&quot;, &quot;password&quot;)

    ' ...

    client.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/ftp-active-vs-passive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Specify different port for FTP</title>
		<link>http://www.lesnikowski.com/blog/specify-different-port-for-ftp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=specify-different-port-for-ftp</link>
		<comments>http://www.lesnikowski.com/blog/specify-different-port-for-ftp/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 09:58:39 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Ftp.dll]]></category>
		<category><![CDATA[FTPS]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2020</guid>
		<description><![CDATA[With Ftp.dll .NET FTP component establishing connection using default port is easy: // C# client.Connect(&#34;ftp.example.com&#34;); ' VB.NET client.Connect(&#34;ftp.example.com&#34;) If you need to specify different port just use overloaded version of Connect method: // C# client.Connect(&#34;ftp.example.com&#34;, 999); // -or- client.Connect(&#34;ftp.example.com&#34;, 999, false); ' VB.NET client.Connect(&#34;ftp.example.com&#34;, 999) ' -or- client.Connect(&#34;ftp.example.com&#34;, 999, False) If you are using SSL: [...]]]></description>
			<content:encoded><![CDATA[<p>With Ftp.dll <a href="http://www.lesnikowski.com/ftp/">.NET FTP component</a> establishing connection using default port is easy:</p>
<pre class="brush: csharp;">
// C#

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

client.Connect(&quot;ftp.example.com&quot;)
</pre>
<p>If you need to <strong>specify different port</strong> just <strong>use overloaded</strong> version of Connect method:</p>
<pre class="brush: csharp;">
// C#

client.Connect(&quot;ftp.example.com&quot;, 999);
// -or-
client.Connect(&quot;ftp.example.com&quot;, 999, false);
</pre>
<pre class="brush: vb;">
' VB.NET

client.Connect(&quot;ftp.example.com&quot;, 999)
' -or-
client.Connect(&quot;ftp.example.com&quot;, 999, False)
</pre>
<p>If you are using SSL:</p>
<pre class="brush: csharp;">
// C#

client.ConnectSSL(&quot;ftp.example.com&quot;, 999);
// -or-
client.Connect(&quot;ftp.example.com&quot;, 999, true);
</pre>
<pre class="brush: vb;">
' VB.NET

client.ConnectSSL(&quot;ftp.example.com&quot;, 999)
' -or-
client.Connect(&quot;ftp.example.com&quot;, 999, True)
</pre>
<p>You can also <strong>specify the port range used in Active mode</strong>.</p>
<pre class="brush: csharp;">
// C#

client.ActiveModePorts = new Range(1024, 1025);
</pre>
<pre class="brush: vb;">
' VB.NET

client.ActiveModePorts = New Range(1024, 1025)
</pre>
<p>You can strong>set the IP address announced to the FTP server in Active mode</strong> data transfer.<br />
By default, the value of this property is IPAddress.None which means that the address of the network interface is used instead. </p>
<pre class="brush: csharp;">
// C#

client.ActiveModeAddress = IPAddress.Parse(&quot;127.0.0.1&quot;);
</pre>
<pre class="brush: vb;">
' VB.NET

client.ActiveModeAddress = IPAddress.Parse(&quot;127.0.0.1&quot;)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/specify-different-port-for-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to access To, Cc, Bcc fields</title>
		<link>http://www.lesnikowski.com/blog/how-to-access-to-cc-bcc-fields/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-access-to-cc-bcc-fields</link>
		<comments>http://www.lesnikowski.com/blog/how-to-access-to-cc-bcc-fields/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 08:03:14 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2009</guid>
		<description><![CDATA[Recently some of the IMail interface address properties changed its types. The reason for this was to handle email groups nicely. Now To, Cc, Bcc and ReplyTo are of IList&#60;MailAddress&#62; type (That is IList Of MailAddress in VB.NET). In those collections you can find two kinds of objectes: MailBox class which represents single mailbox, MailGroup [...]]]></description>
			<content:encoded><![CDATA[<p>Recently some of the IMail interface address properties changed its types. The reason for this was to handle email groups nicely.</p>
<p>Now To, Cc, Bcc and ReplyTo are of <em>IList&lt;MailAddress&gt;</em> type (That is <em>IList Of MailAddress</em> in VB.NET).</p>
<p>In those collections you can find two kinds of objectes:</p>
<ul>
<li><em>MailBox</em> class which represents single mailbox,</li>
<li><em>MailGroup</em> class which represents group of email addresses.</li>
</ul>
<p>Here&#8217;s the simplest code that <strong>prints only mailboxes</strong>:</p>
<pre class="brush: csharp;">
// C#
using Lesnikowski.Mail.Headers;

private string PrintMailboxes(IEnumerable&lt;MailAddress&gt; addresses)
{
   List&lt;string&gt; parts = new List&lt;string&gt;();
   foreach (MailBox mailbox in addresses.OfType&lt;MailBox&gt;())
   {
       parts.Add(string.Format(&quot;{0} &lt;{1}&gt;&quot;,
           mailbox.Name,
           mailbox.Address));
   }
   return string.Join(&quot;, &quot;, parts.ToArray());
}
</pre>
<pre class="brush: vb;">
' VB.NET
Imports Lesnikowski.Mail.Headers

Private Function PrintMailboxes(addresses As IEnumerable(Of MailAddress)) As String
  Dim parts As New List(Of String)()
  For Each mailbox As MailBox In addresses.OfType(Of MailBox)()
      parts.Add(String.Format(&quot;{0} &lt;{1}&gt;&quot;, _
		mailbox.Name, _
		mailbox.Address))
  Next
  Return String.Join(&quot;, &quot;, parts.ToArray())
End Function
</pre>
<p>Here&#8217;s a slightly more complicated version that <strong>handles groups</strong> also:</p>
<pre class="brush: csharp;">
// C#
using Lesnikowski.Mail.Headers;

private string PrintAllAddresses(IEnumerable&lt;MailAddress&gt; addresses)
{
   List&lt;string&gt; parts = new List&lt;string&gt;();
   foreach (MailAddress address in addresses)
   {
       if (address is MailGroup)
       {
           MailGroup group = (MailGroup)address;
           parts.Add(string.Format(&quot;{0} ({1})&quot;,
               group.Name,
               PrintAllAddresses(group.Addresses))); // recursion
       }
       if (address is MailBox)
       {
           MailBox mailbox = (MailBox)address;
           parts.Add(string.Format(&quot;{0} &lt;{1}&gt;&quot;,
               mailbox.Name,
               mailbox.Address));
       }
   }
   return string.Join(&quot;, &quot;, parts.ToArray());
}
</pre>
<pre class="brush: vb;">
' VB.NET
Imports Lesnikowski.Mail.Headers

Private Function PrintAllAddresses(addresses As IEnumerable(Of MailAddress)) As String
   Dim parts As New List(Of String)()
   For Each address As MailAddress In addresses

      If TypeOf address Is MailGroup Then
         Dim group As MailGroup = DirectCast(address, MailGroup)
         parts.Add(String.Format(&quot;{0} ({1})&quot;, _
            group.Name, _
            PrintAllAddresses(group.Addresses))) ' note the recursion
      End If

      If TypeOf address Is MailBox Then
         Dim mailbox As MailBox = DirectCast(address, MailBox)
         parts.Add(String.Format(&quot;{0} &lt;{1}&gt;&quot;, _
            mailbox.Name, _
            mailbox.Address))
      End If

   Next
   Return String.Join(&quot;, &quot;, parts.ToArray())
End Function
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/how-to-access-to-cc-bcc-fields/feed/</wfw:commentRss>
		<slash:comments>0</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>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>
	</channel>
</rss>

