<?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; POP3</title>
	<atom:link href="http://www.lesnikowski.com/blog/index.php/tag/pop3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lesnikowski.com/blog</link>
	<description>.Net</description>
	<lastBuildDate>Wed, 28 Jul 2010 10:10:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The handshake failed due to an unexpected packet format</title>
		<link>http://www.lesnikowski.com/blog/index.php/the-handshake-failed-due-to-an-unexpected-packet-format/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-handshake-failed-due-to-an-unexpected-packet-format</link>
		<comments>http://www.lesnikowski.com/blog/index.php/the-handshake-failed-due-to-an-unexpected-packet-format/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 16:59:37 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[POP3]]></category>
		<category><![CDATA[SMTP]]></category>
		<category><![CDATA[VB.NET]]></category>

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

// C#

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


' VB.NET

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

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

// C#

client.StartTLS();


' VB.NET

client.StartTLS()

In case of POP3:

// C#

client.STLS();


' VB.NET

client.STLS()

In case of SMTP:

// C#

client.StartTLS();


' VB.NET

client.StartTLS()

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

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

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

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=258</guid>
		<description><![CDATA[First you&#8217;ll need an IMAP client or POP3 client to download emails from the server.
The email attachments are downloaded as a part of the message. Attachments are stored within the email as part of a mime tree. Usually Quoted-Printable or Base64 encoding are used. Mail.dll is going to parse such tree for you and expose [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lesnikowski.com/blog/wp-content/uploads/2009/12/mail.png"><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/12/mail.png" alt="" title="mail" width="157" height="149" class="alignleft size-full wp-image-360" /></a>First you&#8217;ll need an <a href="http://www.lesnikowski.com/mail/">IMAP client</a> or <a href="http://www.lesnikowski.com/mail/">POP3 client</a> to download emails from the server.</p>
<p>The email attachments are downloaded as a <strong>part of the message</strong>. Attachments are stored within the email as part of a mime tree. Usually Quoted-Printable or Base64 encoding are used. Mail.dll is going to parse such tree for you and expose all attachments as well known .NET collections.</p>
<p>IMail uses 3 collections for storing attachments:</p>
<ul>
<li><strong>Attachments </strong>- contains all attached documents</li>
<li><strong>Visuals </strong>- contains files that should be &#8216;displayed&#8217; to the user (like images or music that should be played in background)</li>
<li><strong>NonVisuals </strong>- contains attachments that should not be &#8216;displayed&#8217; immediately</li>
</ul>
<p>Following you&#8217;ll find samples of how you can save all attachments to disk using C# and  VB.NET via POP3 and IMAP protocols.</p>
<p><strong>When you use IMAP server:</strong></p>
<pre class="brush: csharp;">
// C# version
using(Imap imap = new Imap())
{
	imap.Connect(&quot;server&quot;);
	imap.Login(&quot;user&quot;, &quot;password&quot;);

	imap.SelectInbox();
	List&lt;long&gt; uids = imap.SearchFlag(Flag.All);
	foreach (long uid in uids)
	{
		string eml = imap.GetMessageByUID(uid);
		IMail email = new MailBuilder()
			.CreateFromEml(eml);

		Console.WriteLine(email.Subject);

		// save all attachments to disk
		email.Attachments.ForEach(mime =&gt; mime.Save(mime.FileName));
	}
	imap.Close(true);
}
</pre>
<p>You can also save attachment to stream: void MimeData.Save(Stream stream)<br />
Or get direct access to it: MemoryStream MimeData.GetMemoryStream()</p>
<pre class="brush: vb;">
' VB.NET version
Using imap As New Imap()
	imap.Connect(&quot;server&quot;)
	imap.Login(&quot;user&quot;, &quot;password&quot;)

	imap.SelectInbox()
	Dim uids As List(Of Long) = imap.SearchFlag(Flag.All)
	For Each uid As Long In uids
		Dim eml As String = imap.GetMessageByUID(uid)
		Dim email As IMail = New MailBuilder()_
			.CreateFromEml(eml)

		Console.WriteLine(email.Subject)

		' save all attachments to disk
		email.Attachments.ForEach(Function(mime) mime.Save(mime.FileName))
	Next
	imap.Close(True)
End Using
</pre>
<p><strong>When you use POP3 server:</strong></p>
<pre class="brush: csharp;">
// C# version
using(Pop3 pop3 = new Pop3())
{
	pop3.Connect(&quot;server&quot;);
	pop3.Login(&quot;user&quot;, &quot;password&quot;);

	foreach (string uid in pop3.GetAll())
	{
		IMail email = new MailBuilder()
			.CreateFromEml(pop3.GetMessageByUID(uid));

		Console.WriteLine(email.Subject);

		// save all attachments to disk
		email.Attachments.ForEach(mime =&gt; mime.Save(mime.FileName));
	}
	pop3.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET version
Using pop3 As New Pop3()
	pop3.Connect(&quot;server&quot;)
	pop3.Login(&quot;user&quot;, &quot;password&quot;)

	For Each uid As String In pop3.GetAll()
		Dim email As IMail = New MailBuilder() _
      			.CreateFromEml(pop3.GetMessageByUID(uid))

		Console.WriteLine(email.Subject)

		' save all attachments to disk
		email.Attachments.ForEach(Function(mime) mime.Save(mime.FileName))
	Next
	pop3.Close(True)
End Using
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/download-email-attachments-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Save raw eml file using IMAP and POP3</title>
		<link>http://www.lesnikowski.com/blog/index.php/save-raw-eml-file-imap-pop3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=save-raw-eml-file-imap-pop3</link>
		<comments>http://www.lesnikowski.com/blog/index.php/save-raw-eml-file-imap-pop3/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 14:03:55 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=344</guid>
		<description><![CDATA[There are times that you need to save raw eml format of the email (for example when you want to report a bug).
This tutorial shows how to use Mail.dll POP3 and IMAP clients  to achieve this goal.
Notice that we are not parsing the emails so we don&#8217;t need to use MailBuilder and IMail classes.
Samples [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/12/mail.png" alt="mail" title="mail" width="157" height="149" class="alignleft size-full wp-image-360" />There are times that you need to save <strong>raw eml format</strong> of the email (for example when you want to report a bug).</p>
<p>This tutorial shows how to use <a href="http://www.lesnikowski.com/mail/">Mail.dll POP3 and IMAP clients </a> to achieve this goal.</p>
<p>Notice that we are not parsing the emails so we don&#8217;t need to use <em>MailBuilder</em> and <em>IMail</em> classes.</p>
<p>Samples provided use both POP3 and IMAP protocols using C# and VB.NET</p>
<p><strong>IMAP version:</strong></p>
<p>The code below will write all emails with specified subject to your c:\ drive:</p>
<pre class="brush: csharp;">
// C# code

using (Imap imap = new Imap())
{
    imap.Connect(&quot;server&quot;);
    // imap.ConnectSSL(&quot;server&quot;); // if you need SSL connection.
    imap.Login(&quot;user&quot;, &quot;password&quot;);

    imap.SelectInbox();

    List&lt;long&gt; uids = imap.Search(
        Expression.Subject(&quot;email subject&quot;));

    foreach (long uid in uids)
    {
        string eml = imap.GetMessageByUID(uid);
        string fileName = string.Format(&quot;c:\\email_{0}.eml&quot;, uid);
        File.WriteAllText(fileName, eml);
    }
    imap.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET code

Using imap As New Imap()
	imap.Connect(&quot;server&quot;)
	' imap.ConnectSSL(&quot;server&quot;) ' if you need SSL connection.
	imap.Login(&quot;user&quot;, &quot;password&quot;)

	imap.SelectInbox()

	Dim uids As List(Of Long) = imap.Search( _
		Expression.Subject(&quot;email subject&quot;))

	For Each uid As Long In uids
		Dim eml As String = imap.GetMessageByUID(uid)
		Dim fileName As String = String.Format(&quot;c:\\email_{0}.eml&quot;, uid)
		File.WriteAllText(fileName, eml)
	Next
	imap.Close(True)
End Using
</pre>
<p><strong>POP3 version:</strong></p>
<p>As POP3 does not allow searching, the code below will write all emails to your c:\ drive:</p>
<pre class="brush: csharp;">
// C# code

using (Pop3 pop3 = new Pop3())
{
    pop3.Connect(&quot;server&quot;);
    // pop3.ConnectSSL(&quot;server&quot;); // if you need SSL connection.
    pop3.Login(&quot;user&quot;, &quot;password&quot;);

    foreach (string uid in pop3.GetAll())
    {
        string eml = pop3.GetMessageByUID(uid));
        string fileName = string.Format(&quot;c:\\email_{0}.eml&quot;, uid);
        File.WriteAllText(fileName, eml);
    }
    pop3.Close(true);
}
</pre>
<pre class="brush: vb;">
' VB.NET code

Using pop3 As New Pop3()
	pop3.Connect(&quot;server&quot;)
	' pop3.ConnectSSL(&quot;server&quot;); ' if you need SSL connection.
	pop3.Login(&quot;user&quot;, &quot;password&quot;)

  For Each uid As String In pop3.GetAll()
		Dim eml As String = pop3.GetMessageByUID(uid)
		Dim fileName As String = String.Format(&quot;c:\\email_{0}.eml&quot;, uid)
		File.WriteAllText(fileName, eml)
	Next
	pop3.Close(True)
End Using
</pre>
<p>You can download Mail.dll at: <a href="http://www.lesnikowski.com/mail/">Mail.dll .NET email component</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/save-raw-eml-file-imap-pop3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Download emails from GMail via POP3</title>
		<link>http://www.lesnikowski.com/blog/index.php/download-emails-gmail-pop3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=download-emails-gmail-pop3</link>
		<comments>http://www.lesnikowski.com/blog/index.php/download-emails-gmail-pop3/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:54:04 +0000</pubDate>
		<dc:creator>Pawel Lesnikowski</dc:creator>
				<category><![CDATA[Component]]></category>
		<category><![CDATA[Mail.dll]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://www.lesnikowski.com/blog/?p=288</guid>
		<description><![CDATA[
Accessing Gmail with POP3 is a bit different that accessing other POP3 servers. Still is quite easy with Mail.dll IMAP client. Remember that POP3 protocol unlike IMAP does not store the unseen information on the server.
Mail.dll has of course IMAP support
First we need to make sure that POP3 access is enabled for your GMail account.

Go [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail.png" alt="gmail" title="gmail" width="131" height="61" class="alignleft size-full wp-image-271" /><br />
Accessing Gmail with POP3 is a bit different that accessing other POP3 servers. Still is quite easy with <a href="http://www.lesnikowski.com/mail/">Mail.dll IMAP client</a>. Remember that POP3 protocol unlike IMAP does not store the unseen information on the server.</p>
<p>Mail.dll has of course <a href="http://www.lesnikowski.com/blog/index.php/download-emails-from-gmail/">IMAP support</a></p>
<p>First we need to make sure that POP3 access is enabled for your GMail account.</p>
<ol>
<li>Go to <strong>GMail settings</strong>:
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail_settings.png" alt="gmail_settings" title="gmail_settings" width="381" height="75" class="alignnone size-full wp-image-272" />
</li>
<li>Then select <strong>&#8216;Forwarding and POP/IMAP&#8217;</strong> tab:
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail_settings_tab.png" alt="gmail_settings_tab" title="gmail_settings_tab" width="463" height="61" class="alignnone size-full wp-image-277" />
</li>
<li>And check one of the <strong>&#8216;Enable &#8230;&#8217;</strong> options in <strong>&#8216;IMAP Access&#8217;</strong> section:
<p><img src="http://www.lesnikowski.com/blog/wp-content/uploads/2009/11/gmail_settings_pop3.png" alt="gmail_settings_pop3" title="gmail_settings_pop3" width="605" height="116" class="alignnone size-full wp-image-297" />
</li>
<li>
GMail behaves differently than other POP3 servers and its POP3 configuration may be sometimes confusing.<br />
Luckily you can configure what you expect from it. Here&#8217;s the value list of drop down list called <strong>&#8220;When messages are accessed with POP&#8221;</strong> and the Gmail&#8217;s behavior:</p>
<ol>
<li><strong>&#8220;delete Gmail&#8217;s copy&#8221;</strong>: Message is deleted by issuing GetMessage command.</li>
<li><strong>&#8220;keep Gmail&#8217;s copy in the Inbox&#8221;</strong>: Message stays in the Inbox, Web interface says it&#8217;s unread, however message is <strong>not</strong> received for the second time using POP3 client.</li>
<li><strong>&#8220;archive Gmail&#8217;s copy&#8221;</strong>: Message is deleted by issuing GetMessage command, however it is possible to find it using web interface.</li>
</ol>
</li>
<li>Now you are able to connect to your GMail account with <strong>Mail.dll POP3 client</strong>.</li>
</ol>
<p>If you want to have a greater control over your mail you should use<br />
<a href="http://www.lesnikowski.com/blog/index.php/download-emails-from-gmail/">Mail.dll .NET IMAP client</a>. You can easily move messages between folders (IMAP calls them mailboxes) and flag them.</p>
<p>Remember that GMail only allows <strong>secure SSL</strong> connections so we need to use <em>ConnectSSL</em> method.</p>
<pre class="brush: csharp;">
// C# code:

using(Pop3 pop3 = new Pop3())
{
	pop3.ConnectSSL(&quot;pop.gmail.com&quot;);
	pop3.Login(&quot;your_email@gmail.com&quot;, &quot;password&quot;);

	foreach (string uid in pop3.GetAll())
	{
		string eml = pop3.GetMessageByUID(uid);
		IMail mail= new MailBuilder()
			.CreateFromEml(eml);

		Console.WriteLine(mail.Subject);
		Console.WriteLine(mail.TextDataString);
	}
	pop3.Close(false);
}
</pre>
<pre class="brush: vb;">
' VB.NET code:

Using pop3 As New Pop3()
	pop3.ConnectSSL(&quot;pop.gmail.com&quot;)
	pop3.Login(&quot;your_email@gmail.com&quot;, &quot;password&quot;)

  For Each uid As String In pop3.GetAll()
    Dim email As IMail = New MailBuilder() _
        .CreateFromEml(pop3.GetMessageByUID(uid))
    Console.WriteLine(email.Subject)
		Console.WriteLine(mail.TextDataString)
	Next
	pop3.Close(False)
End Using
</pre>
<p>If you like the idea of simple GMail access just give it a try for yourself and download it at: <a href="http://www.lesnikowski.com/mail/">Mail.dll .NET email</a> component</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lesnikowski.com/blog/index.php/download-emails-gmail-pop3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
