<?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; Mail.dll</title>
	<atom:link href="http://www.lesnikowski.com/blog/tag/mail-dll/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>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>Reply to an email</title>
		<link>http://www.lesnikowski.com/blog/reply-to-email/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reply-to-email</link>
		<comments>http://www.lesnikowski.com/blog/reply-to-email/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 09:53:34 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[SMTP]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2188</guid>
		<description><![CDATA[You can use Mail.dll to reply to an HTML or plain-text email. ReplyBuilder class allows you to specify custom HTML and plain-text templates for the reply. Mail.dll will parse HTML extract body part, and build-in template engine will do the rest. The next great thing is that plain-text version of the email is generated automatically. [...]]]></description>
			<content:encoded><![CDATA[<p>You can use Mail.dll to reply to an HTML or plain-text email.</p>
<p>ReplyBuilder class allows you to specify custom HTML and plain-text templates for the reply. Mail.dll will parse HTML extract body part, and build-in template engine will do the rest.</p>
<p>The next great thing is that plain-text version of the email is generated automatically.</p>
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2011/12/reply.png" alt="" title="reply" width="429" height="388" class="aligncenter size-full wp-image-2197" /></p>
<pre class="brush: csharp;">
// C#

IMail original = ...;

ReplyBuilder replyBuilder = original.Reply();
// You can specify your own custom template:
replyBuilder.HtmlReplyTemplate =
    &quot;[Html]&quot; +
    &quot;&lt;br /&gt;&lt;br /&gt;&quot; +
    &quot;On [Original.Date] [Original.Sender.Name] wrote:&quot; +
    &quot;&lt;blockquote &quot; +
        &quot;style='margin-left: 1em; &quot; +
        &quot;padding-left: 1em; &quot; +
        &quot;border-left: 1px #ccc solid;'&gt;&quot; +
    &quot;[QuoteHtml]&quot; +
    &quot;&lt;/blockquote&gt;&quot;;

replyBuilder.Html =
    &quot;Alice, &lt;br/&gt;&lt;br/&gt;thanks for your email.&quot;;

MailBuilder builder = replyBuilder.ReplyToAll(
    new MailBox(&quot;bob@example.org&quot;, &quot;Bob&quot;));

// You can add attachments to your reply
//builder.AddAttachment(&quot;report.csv&quot;);

IMail reply = builder.Create();

using (Smtp smtp = new Smtp())
{
    smtp.Connect(&quot;smtp.example.com&quot;); // or ConnectSSL
    smtp.Login(&quot;user&quot;, &quot;password&quot;);
    smtp.SendMessage(reply);
    smtp.Close();
}
</pre>
<pre class="brush: vb;">
' VB.NET

Dim original As IMail = ...

Dim replyBuilder As ReplyBuilder = original.Reply()

' You can specify your own custom template:
replyBuilder.HtmlReplyTemplate = _
    &quot;[Html]&quot; + _
    &quot;&lt;br /&gt;&lt;br /&gt;&quot; + _
    &quot;On [Original.Date] [Original.Sender.Name] wrote:&quot; + _
    &quot;&lt;blockquote &quot; + _
        &quot;style='margin-left: 1em; &quot; + _
        &quot;padding-left: 1em; &quot; + _
        &quot;border-left: 1px #ccc solid;'&gt;&quot; + _
    &quot;[QuoteHtml]&quot; + _
    &quot;&lt;/blockquote&gt;&quot;

replyBuilder.Html = _
    &quot;Alice, &lt;br/&gt;&lt;br/&gt;thanks for your email.&quot;

Dim builder As MailBuilder = replyBuilder.ReplyToAll( _
    New MailBox(&quot;bob@example.org&quot;, &quot;Bob&quot;))

' You can add attachments to your reply
'builder.AddAttachment(&quot;report.csv&quot;)

Dim reply As IMail = builder.Create()

Using smtp As New Smtp()
	smtp.Connect(&quot;smtp.example.com&quot;)
	smtp.Login(&quot;user&quot;, &quot;password&quot;) ' or ConnectSSL
	smtp.SendMessage(reply)
	smtp.Close()
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/reply-to-email/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Extract plain text from HTML email</title>
		<link>http://www.lesnikowski.com/blog/extract-plain-text-from-html-email/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extract-plain-text-from-html-email</link>
		<comments>http://www.lesnikowski.com/blog/extract-plain-text-from-html-email/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 16:59:24 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Mail.dll]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2185</guid>
		<description><![CDATA[Mail.dll MIME and Email API’s may be used to extract the plain-text body and HTML body from an email message. If a message contains plain-text, no conversion is necessary. It’s simply a matter of using the Text property of IMail interface. If however the email does not contain plain-text and only HTML content is available [...]]]></description>
			<content:encoded><![CDATA[<p>Mail.dll MIME and Email API’s may be used to extract the plain-text body and HTML body from an email message.</p>
<p>If a message contains plain-text, no conversion is necessary. It’s simply a matter of using the Text property of IMail interface.</p>
<p>If however the email does not contain plain-text and only HTML content is available <strong>GetTextFromHtml </strong>method may be used to <strong>convert the HTML to plain-text</strong>.</p>
<p>The internal conversion process is much more sophisticated than can be accomplished with the simple regular-expression code. This is more than simply removing HTML tags from an HTML document.</p>
<p>Mail.dll contains <strong>full-blown HTML parser</strong> that handles script tags, comments, CDATA and even incorrect HTML.</p>
<p>The following C# and VB.NET code extracts plain-text from the HTML body of the email message:</p>
<pre class="brush: csharp;">
// C#

IMail email = ...

string text = email.Text;
if (string.IsNullOrEmpty(text) &amp;&amp; email.IsHtml)
{
    text = email.GetTextFromHtml();
}
Console.WriteLine(text);
</pre>
<p>The following C# code extracts the HTML body from this MIME message and converts the HTML to plain-text:</p>
<pre class="brush: vb;">
' VB.NET

Dim email As IMail = ...

Dim text As String = email.Text
If String.IsNullOrEmpty(text) AndAlso email.IsHtml Then
	text = email.GetTextFromHtml()
End If
Console.WriteLine(text)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/extract-plain-text-from-html-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import certificate, private or public keys (PEM, CER, PFX)</title>
		<link>http://www.lesnikowski.com/blog/import-certificate-private-public-keys-pem-cer-pfx/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=import-certificate-private-public-keys-pem-cer-pfx</link>
		<comments>http://www.lesnikowski.com/blog/import-certificate-private-public-keys-pem-cer-pfx/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 12:09:58 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[DKIM]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[SMIME]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=2089</guid>
		<description><![CDATA[Encrypted private key, RSA private key in PEM file: PEM stands for Privacy Enhanced Mail format. PemReader pem = new PemReader(); RSACryptoServiceProvider rsa = pem.ReadEncryptedPrivateKeyFromFile( &#34;EncryptedPrivateKey.pem&#34;, // &#34;EncryptedRSAPrivateKey.pem&#34; &#34;cypher&#34;); This code handles following formats: PKCS #8 EncryptedPrivateKeyInfo Encrypted Format: -----BEGIN ENCRYPTED PRIVATE KEY----- MIICojAcBgoqhkiG9w0BD ..... Private Key (Traditional SSLeay RSAPrivateKey format) Encrypted: -----BEGIN RSA PRIVATE [...]]]></description>
			<content:encoded><![CDATA[<h2>Encrypted private key, RSA private key in <strong>PEM</strong> file:</h2>
<p>PEM stands for Privacy Enhanced Mail format.</p>
<pre class="brush: csharp;">
PemReader pem = new PemReader();
RSACryptoServiceProvider rsa = pem.ReadEncryptedPrivateKeyFromFile(
   &quot;EncryptedPrivateKey.pem&quot;, // &quot;EncryptedRSAPrivateKey.pem&quot;
   &quot;cypher&quot;);
</pre>
<p>This code handles following formats:</p>
<p> PKCS #8  EncryptedPrivateKeyInfo Encrypted Format:<br />
<code><br />
        -----BEGIN ENCRYPTED PRIVATE KEY-----<br />
        MIICojAcBgoqhkiG9w0BD .....<br />
</code></p>
<p>Private Key (Traditional SSLeay RSAPrivateKey format) Encrypted:<br />
<code><br />
        -----BEGIN RSA PRIVATE KEY-----<br />
        Proc-Type: 4,ENCRYPTED<br />
        DEK-Info: DES-EDE3-CBC,24A667C253F8A1B9</p>
<p>        mKz .....<br />
</code></p>
<p>You can remove the passphrase from the private key:<br />
openssl rsa -in EncryptedPrivateKey.pem -out PrivateKey.pem</p>
<h2>Unencrypted private key in <strong>PEM</strong> file:</h2>
<pre class="brush: csharp;">
PemReader pem = new PemReader();
RSACryptoServiceProvider rsa = pem.ReadPrivateKeyFromFile(
   &quot;PrivateKey.pem&quot;);
</pre>
<p>This code handles following formats:</p>
<p>PKCS #8  PrivateKeyInfo Unencrypted:<br />
<code><br />
        -----BEGIN PRIVATE KEY-----<br />
        MIICdgIBADANBgkqhkiG9w0B ......<br />
</code></p>
<p>Private Key (Traditional SSLeay RSAPrivateKey format) Unencrypted:<br />
<code><br />
        -----BEGIN RSA PRIVATE KEY-----<br />
        MIICXQIBAAKBgQCcHVm  .....<br />
</code></p>
<h2>Public key in <strong>PEM</strong> file:</h2>
<pre class="brush: csharp;">
PemReader pem = new PemReader();
RSACryptoServiceProvider rsa = pem.ReadPublicKeyFromFile(
   &quot;PublicKey.pem&quot;)
</pre>
<p>This code handles following formats:</p>
<p>Public Key (SubjecPublicKeyInfo):<br />
<code><br />
        -----BEGIN PUBLIC KEY-----<br />
        MIGfMA0GCSqGSIb3DQEB .....<br />
</code></p>
<h2>Certificate/private key in <strong>PFX</strong> file:</h2>
<pre class="brush: csharp;">
X509Certificate2 certificate  = new X509Certificate2(
   &quot;certificate.pfx&quot;,
   &quot;&quot;,
   X509KeyStorageFlags.PersistKeySet)

if (certificate.HasPrivateKey)
{
  using (RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)certificate.PrivateKey)
  {
  }
}
</pre>
<h2>Certificate in <strong>PEM/CER</strong> file</h2>
<p>Note: The private key is never stored in a .pem/.cer file.</p>
<pre class="brush: csharp;">
X509Certificate2 certificate = new X509Certificate2(
   &quot;certificate.cer&quot;);
</pre>
<p>-or-</p>
<pre class="brush: csharp;">
PemReader pem = new PemReader();
X509Certificate2 certificate = pem.ReadCertificateFromFile(
   &quot;certificate.cer&quot;);
</pre>
<p>This code handles following formats:</p>
<p><code><br />
        -----BEGIN CERTIFICATE-----<br />
        MIIFsTCCA5mgAwIBAgIKYQ .....<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/import-certificate-private-public-keys-pem-cer-pfx/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>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>
	</channel>
</rss>

