POP3 SSH Tunneling (Port Forwarding)

ASP: POP3 SSH Tunneling (Port Forwarding)
SQL Server: POP3 SSH Tunneling (Port Forwarding)
C#: POP3 SSH Tunneling (Port Forwarding)
C++: POP3 SSH Tunneling (Port Forwarding)
MFC: POP3 SSH Tunneling (Port Forwarding)
C: POP3 SSH Tunneling (Port Forwarding)
Delphi: POP3 SSH Tunneling (Port Forwarding)
Visual FoxPro: POP3 SSH Tunneling (Port Forwarding)
Java: POP3 SSH Tunneling (Port Forwarding)
Perl: POP3 SSH Tunneling (Port Forwarding)
PHP: POP3 SSH Tunneling (Port Forwarding)
Python: POP3 SSH Tunneling (Port Forwarding)
Ruby: POP3 SSH Tunneling (Port Forwarding)
VB.NET: POP3 SSH Tunneling (Port Forwarding)
Visual Basic: POP3 SSH Tunneling (Port Forwarding)
VBScript: POP3 SSH Tunneling (Port Forwarding)

POP3 Headers and Attachment Info

The POP3 protocol is not very feature rich. To download an email “header” the POP3 client must issue a “TOP” command. The following text is from RFC 1939 and describes the response to the TOP command:

...
After the initial +OK, the
POP3 server sends the headers of the message, the blank
line separating the headers from the body, and then the
number of lines of the indicated message's body, being
careful to byte-stuff the termination character (as with
all multi-line responses).
...

What this means is that the response will contain the N raw lines following the email header. An email with attachments is typically a multipart/mixed email and therefore the lines following the initial MIME header are the MIME sub-headers and sub-header bodies. For example, consider the following email which contains 3 GIF image attachments:

MIME-Version: 1.0
Date: Tue, 04 Nov 2008 14:54:33 -0600
Message-ID: <CHILKAT-MID-1adb0da5-2646-edac-1f79-9e288b0677ac@CK2007>
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Subject: This is a test
From: "Support" <support@something-123.com>
Return-Path: support@something-123.com
To: "Admin" <admin@something-123.com>
Content-Type: multipart/mixed;
	boundary="-----_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX"

This is a multi-part message in MIME format.

-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
This is line 6
This is line 7
This is line 8
This is line 9

-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
Content-Type: image/gif;
	name="small1.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	 filename="small1.gif"

R0lGODlhFAAUAJH/AP///wD/PACLIQAAACwAAAAAFAAUAEACFoyPqcvtLoaclL6Ls968+w+G
4kiWYwEAOw==

-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
Content-Type: image/gif;
	name="small2.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	 filename="small2.gif"

R0lGODlhFAAUAJH/AP///wD/PACLIQAAACwAAAAAFAAUAEACFoyPqcvtLoaclL6Ls968+w+G
4kiWYwEAOw==

-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
Content-Type: image/gif;
	name="small3.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	 filename="small3.gif"

R0lGODlhFAAUAJH/AP///wD/PACLIQAAACwAAAAAFAAUAEACFoyPqcvtLoaclL6Ls968+w+G
4kiWYwEAOw==

-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX--

A POP3 server would respond to a “TOP 25” lines command by sending the following:
(The line numbers enclosed in parentheses are not actually included in the POP3 server’s response)

MIME-Version: 1.0
Date: Tue, 04 Nov 2008 14:54:33 -0600
Message-ID: <CHILKAT-MID-1adb0da5-2646-edac-1f79-9e288b0677ac@CK2007>
X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com)
X-Priority: 3 (Normal)
Subject: This is a test
From: "Support" <support@something-123.com>
Return-Path: support@something-123.com
To: "Admin" <admin@something-123.com>
Content-Type: multipart/mixed;
	boundary="-----_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX"

(1)This is a multi-part message in MIME format.
(2)
(3)-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
(4)Content-Type: text/plain
(5)Content-Transfer-Encoding: quoted-printable
(6)
(7)This is line 1
(8)This is line 2
(9)This is line 3
(10)This is line 4
(11)This is line 5
(12)This is line 6
(13)This is line 7
(14)This is line 8
(15)This is line 9
(16)
(17)-------_chilkat_5ad_e1df_7b63f7c5.559182f3_.MIX
(18)Content-Type: image/gif;
(19)	name="small1.gif"
(20)Content-Transfer-Encoding: base64
(21)Content-Disposition: attachment;
(22)	 filename="small1.gif"
(23)
(24)R0lGODlhFAAUAJH/AP///wD/PACLIQAAACwAAAAAFAAUAEACFoyPqcvtLoaclL6Ls968+w+G
(25)4kiWYwEAOw==

The POP3 client has no knowledge of the attachments following the 1st 25 lines. The POP3 client, if it’s able to parse the prematurely chopped-off MIME, may have knowledge of attachments that might have been included in the response (it would depend on how good the MIME parser is capable of dealing with prematurely terminated MIME). You can see that no matter how many header lines are retrieved, you can never be sure of receiving all the attachments (or even knowing about them) unless the entire email is downloaded. For example, you could have an email with two attachments — one very large one and one very small one. If the small one follows the large one, you’ll never see it unless you download the full contents of the large attachment to get at the small attachment that follows…

Binding to an IP

Question:

I have a question about ‘binding’ Chilkat EMAIL to a specific socket in .NET. The reason why I’m asking is; the servers on which I’m using the component have multiple NIC’s and each NIC can have multiple IP’s assigned. I need to software-select through which IP the mails shall be sent.

Answer:

The Chilkat Mailman object provides a ClientIpAddress property that may be set to control the IP address used for binding.

-ERR Mailbox Locked

If you see this error when trying to login to a POP3 server, it most likely means that the server is only allowing a single connection (i.e. session) at a time for each mailbox, and than another user already has mailbox open.  It could also mean that the POP3 administrator temporarily locked the mailbox to prevent access.

No messages in POP3 mailbox?

Question:
I am reading my POP3 mailbox by calling mailman.CopyMail. It returns a bundle object, but the bundle.MessageCount = 0. I know there are emails in the mailbox. What happened?

Answer:
The most common mistake is that you’re looking at your email using a program such as Outlook and your emails have already been downloaded and removed from the POP3 server. After calling CopyMail, check the contents of the mailman’s Pop3SessionLog property — it is a string that may be displayed in your application. You should see the entire conversation between POP3 client (the Chilkat email component) and the POP3 server, including the response from the POP3 server that indicates 0 messages in the mailbox.

UIDL Max Size? (for POP3)

Question:
I’m trying to find out the maximum size of the POP3 UIDL.
I’ve found various POP3 specs, but they dont list field sizes.
Do you know the max size or can you give me any links to this info?

Answer:

(from RFC 1939) The unique-id of a message is an arbitrary server-determined
string, consisting of one to 70 characters in the range 0x21
to 0x7E, which uniquely identifies a message within a
maildrop and which persists across sessions. This
persistence is required even if a session ends without
entering the UPDATE state. The server should never reuse an
unique-id in a given maildrop, for as long as the entity
using the unique-id exists.

IMPORTANT: It has been found that some servers produce longer UIDLs than the max indicated by the POP3 RFC specification. If using a database field to store the UIDL, it’s best to make it 255 chars.

POP3 Change Password Programmatically?

Question:

Is it possible to change the password for a POP3 account or create a POP3 account?

Answer:

Account management is not part of the POP3 protocol and therefore it is not possible to change POP3 passwords programmatically.

Outlook vs. Mail Servers

Question:

I am using your email ActiveX control and wanted to know if there is a way to update MS Outlook in the sent folder with the email I am sending with your control?

Answer:

Email clients communicate with email servers using a well-known protocol. Email clients do not generally communicate with other email clients. Here is a non-exhaustive list of email clients, servers, and protocols:

Email Protocols

  • IMAP (for reading email. Email and folders managed on server.)
  • POP3 (for reading email. No folders on server, email generally downloaded and managed locally.)
  • SMTP (for sending email)
  • MAPI (proprietary to Microsoft)

Email Clients and the protocols spoken

  • Microsoft Outlook (POP3, IMAP, SMTP, MAPI)
  • Mozilla Thunderbird (POP3, IMAP, SMTP)
  • Eudora (POP3, IMAP, SMTP)
  • Chilkat Email Component (POP3, SMTP)
  • Chilkat IMAP Component (IMAP)

Email Servers (and the protocols spoken)

  • Exchange Server – speaks POP3, IMAP, SMTP, MAPI
  • MailEnable – speaks POP3, IMAP, SMTP
  • IMail Server – speaks POP3, IMAP, SMTP

Email clients speak the client-side of a protocol.
Email servers speak the server-side of a protocol.

Email clients do not speak to other email clients.
Email client applications keep a local “database” of some sort (file-based or RDB-based) of email accounts, sent-email, and (for POP3) email organized in folders.
Email client components (such as Chilkat) provide the ability to communicate with email servers. The persistence of emails locally is generally left to the application.

Client-to-Server communications with Exchange Server are no different than with any other email server (except if MAPI is used, or if an Exchange-Server specific authentication method is used).

Microsoft Office provides an “Outlook API” to allow applications to communicate with Outlook local stores.

It makes no more sense for Chilkat to communicate with Outlook than it does for Mozilla Thunderbird to communicate with Outlook. (Because client-to-client communications don’t make any sense. Only client-to-server makes sense.)

POP3 Sessions w.r.t. New Email and Deleting Email

The POP3 protocol is such that a new session is started after a successful login. The session is a snapshot of the existing emails in the mailbox. Any new email that arrives during the session will not be seen until the session is ended (i.e. you logout) and a new session is started. Also, emails marked for deletion are not actually deleted until the session ends.

If you are writing a program to delete multiple emails, then session management becomes important. If your program loses connection to the POP3 server while marking the Nth email for deletion, then none of the emails will have actually been deleted. (Internally, the POP3 server requires a QUIT command to be sent before the TCP/IP socket disconnect. The Chilkat Pop3EndSession method does this.)

The mailman.ImmediateDelete property controls whether the POP3 session is automatically ended and re-established in each of the various delete methods. If set to false, then the POP3 session remains open after each email is marked for delete. This is more efficient when marking many emails for deletion, but your code will need to recover appropriately if a connection is lost before marking the last email for deletion and cleanly closing the POP3 session.