Using Sockets/Ports to listen for POP3 traffic 
Author Message
 Using Sockets/Ports to listen for POP3 traffic

Does anyone have any suggestions on how to listen on Port 110 for POP3
traffic.

It seems simple enough in Outlook to monitor for incoming email, but
my application may not want to rely on any one particular client.
The idea here is to retrieve email traffic without regard to the email
client software.
I understand you can use event sinks if you are running your own SMTP
server, but this will not allways be the case.
Maybe the underlying question is if two processes can use the same
socket/port - i.e. The email client that does its regular business,
and my dotnet app retrieveing some information as it travels down to
the email client from the POP3 server.
Not having to buy/create your own email client, and simply using the
existing one (and somehow its reading its stream) would be the
preferred situation.

Any ideas/thoughts/concepts greatly appreciated.

Thanks in advance



Thu, 11 Aug 2005 12:30:25 GMT  
 Using Sockets/Ports to listen for POP3 traffic


Quote:
> Does anyone have any suggestions on how to listen on Port 110 for POP3
> traffic.

> It seems simple enough in Outlook to monitor for incoming email, but
> my application may not want to rely on any one particular client.
> The idea here is to retrieve email traffic without regard to the email
> client software.

I'm really not understanding what you want to do; Outlook doesn't listen on
port 110; it contacts mail servers which are listening on port 110, says
"hey, what you got for me on this account" and downloads whatever it's got

Quote:
> I understand you can use event sinks if you are running your own SMTP
> server, but this will not allways be the case.
> Maybe the underlying question is if two processes can use the same
> socket/port - i.e. The email client that does its regular business,
> and my dotnet app retrieveing some information as it travels down to
> the email client from the POP3 server.

again, it's not clear what you're tring to accomplish .. but I don't see why
you could not build a service which contacts the email server at interval X,
looks at the emails waiting and does whatever it is you want it to do; it
obviously does not need to delete the messages, so Outlook can still get
them per the usual routine
Quote:
> Not having to buy/create your own email client, and simply using the
> existing one (and somehow its reading its stream) would be the
> preferred situation.



Fri, 12 Aug 2005 01:09:38 GMT  
 Using Sockets/Ports to listen for POP3 traffic
<inline>

Quote:
> but I don't see why
> you could not build a service which contacts the email server at interval
X,
> looks at the emails waiting and does whatever it is you want it to do; it
> obviously does not need to delete the messages, so Outlook can still get
> them per the usual routine

Is this what you need to do? I found a document somewhere on the web that
documented all of the POP3 commands, sent to the server and the responses
receieved. In effect, you are creating your own client. However, Outlook
does delete the email messages off the server, and so if Outlook downloaded
the messages before your client got a look, then the messages would be gone.

--
==============================================
Happy To Help,
Tom Spink

http://dotnetx.betasafe.com >> VB, VB.NET, C#, C++ Code

Please respond to the newsgroups, so all can benefit.

One day

Quote:



> > Does anyone have any suggestions on how to listen on Port 110 for POP3
> > traffic.

> > It seems simple enough in Outlook to monitor for incoming email, but
> > my application may not want to rely on any one particular client.
> > The idea here is to retrieve email traffic without regard to the email
> > client software.

> I'm really not understanding what you want to do; Outlook doesn't listen
on
> port 110; it contacts mail servers which are listening on port 110, says
> "hey, what you got for me on this account" and downloads whatever it's got

> > I understand you can use event sinks if you are running your own SMTP
> > server, but this will not allways be the case.
> > Maybe the underlying question is if two processes can use the same
> > socket/port - i.e. The email client that does its regular business,
> > and my dotnet app retrieveing some information as it travels down to
> > the email client from the POP3 server.

> again, it's not clear what you're tring to accomplish .. but I don't see
why
> you could not build a service which contacts the email server at interval
X,
> looks at the emails waiting and does whatever it is you want it to do; it
> obviously does not need to delete the messages, so Outlook can still get
> them per the usual routine

> > Not having to buy/create your own email client, and simply using the
> > existing one (and somehow its reading its stream) would be the
> > preferred situation.



Fri, 12 Aug 2005 01:57:55 GMT  
 Using Sockets/Ports to listen for POP3 traffic

Hi Liz, thanks for getting back.

Perhaps I might not have been as clear as I could be.
What I am trying to accomplish is 'tagging' a contact manager with
emails received using an arbitrary email client - by somehow parsing
out the email address as it travels down to the email client.
The user would just use their regular email package, and (somehow) my
dot net would pick up on the tiime when the email client retrieves the
email.

If I hear you correctly, it might be possible for my dotnet app to
query the POP3 server directly, and not actually delete the email on
the server. While this would be one way of doing it, my app would
somehow have to ensure it does not tag duplicate emails. I think the
specifications for email messages includes some sort of unique message
ID (at least within a particular email server), but I was hoping not
to have to do that.

In essence, what I am trying to do is trap the moment the client
connects to the email server, and somehow trap/sniff what comes down
the wire - still having the strteam end up at the normal email
client..

I don't know if this is even possible, but I thought personal
anti-virus/firewall software would work similarly.

Thanks again

Quote:



>> Does anyone have any suggestions on how to listen on Port 110 for POP3
>> traffic.

>> It seems simple enough in Outlook to monitor for incoming email, but
>> my application may not want to rely on any one particular client.
>> The idea here is to retrieve email traffic without regard to the email
>> client software.

>I'm really not understanding what you want to do; Outlook doesn't listen on
>port 110; it contacts mail servers which are listening on port 110, says
>"hey, what you got for me on this account" and downloads whatever it's got

>> I understand you can use event sinks if you are running your own SMTP
>> server, but this will not allways be the case.
>> Maybe the underlying question is if two processes can use the same
>> socket/port - i.e. The email client that does its regular business,
>> and my dotnet app retrieveing some information as it travels down to
>> the email client from the POP3 server.

>again, it's not clear what you're tring to accomplish .. but I don't see why
>you could not build a service which contacts the email server at interval X,
>looks at the emails waiting and does whatever it is you want it to do; it
>obviously does not need to delete the messages, so Outlook can still get
>them per the usual routine

>> Not having to buy/create your own email client, and simply using the
>> existing one (and somehow its reading its stream) would be the
>> preferred situation.



Fri, 12 Aug 2005 02:05:08 GMT  
 Using Sockets/Ports to listen for POP3 traffic
Hi Liz, thanks for getting back,

What I am trying to do is to somehow trap the moment that the email
client starts downloading the email from the server and somehow have
my program:

1) Be notified when the download starts
2) Read the stream for contact information (e.g. incoming email
address)

If I understand you correctly, I can read the server directly and
simply leave the emails on the server without deleting them.
This would not be my preferred solution as I am trying to keep what
actually comes down to the client and what gets 'tagged' in my program
in sync.
I think the specifications for email do inlude some kind of unique
message number (at least within one particular server), but I am
trying to stay away frrom having to do something like that.

I thing personal anti-virus/firewall software may do something
similar, but I may be brking up the wrong tree

Plz. excuse is this is a duplicate post, but I cannot seem to find my
response to your first post-back.

Quote:



>> Does anyone have any suggestions on how to listen on Port 110 for POP3
>> traffic.

>> It seems simple enough in Outlook to monitor for incoming email, but
>> my application may not want to rely on any one particular client.
>> The idea here is to retrieve email traffic without regard to the email
>> client software.

>I'm really not understanding what you want to do; Outlook doesn't listen on
>port 110; it contacts mail servers which are listening on port 110, says
>"hey, what you got for me on this account" and downloads whatever it's got

>> I understand you can use event sinks if you are running your own SMTP
>> server, but this will not allways be the case.
>> Maybe the underlying question is if two processes can use the same
>> socket/port - i.e. The email client that does its regular business,
>> and my dotnet app retrieveing some information as it travels down to
>> the email client from the POP3 server.

>again, it's not clear what you're tring to accomplish .. but I don't see why
>you could not build a service which contacts the email server at interval X,
>looks at the emails waiting and does whatever it is you want it to do; it
>obviously does not need to delete the messages, so Outlook can still get
>them per the usual routine

>> Not having to buy/create your own email client, and simply using the
>> existing one (and somehow its reading its stream) would be the
>> preferred situation.



Fri, 12 Aug 2005 02:56:03 GMT  
 Using Sockets/Ports to listen for POP3 traffic

Quote:

>1) Be notified when the download starts
>2) Read the stream for contact information (e.g. incoming email
>address)

If you really must do that when the client downloads email then I don't think
you have any choice but to have the client connect through a proxy server and
monitor the flow of data.  Such a proxy is relatively simple to write in .net -
and if you want components that will handle all email message
parsing/construction you should take a look at my mail components:
www.abderaware.com.

--
           Abderaware
    Fine Components For .NET
   Turn on, tune in, download.



Fri, 12 Aug 2005 06:28:04 GMT  
 Using Sockets/Ports to listen for POP3 traffic
Okay, RFC 791 defines, essentially, what nneds to be to done here.

You need to create two  no-blocking sockets, set some properties for each
and then monitor packate activity.

Most of the code examples are done in CSharp.Since I don't believe that
VB.Net programmers ought to get cuaght up into purchasing third party
controls and libraries again -- like we did when VB3 came out, I converted
the C# code to VB.

This goes into a module:

Imports System.Runtime.InteropServices

Imports System.Net.Sockets

Module Module1

   <StructLayout(LayoutKind.Explicit)> _
    Public Structure IpHeader
        <FieldOffset(0)> Public ip_verlen As Byte 'IP version and IP Header
length
        <FieldOffset(1)> Public ip_tos As Byte 'Type of service
        <FieldOffset(2)> Public ip_totallength As Short 'total length of the
packet
        <FieldOffset(4)> Public ip_id As Short 'unique identifier
        <FieldOffset(6)> Public ip_offset As Byte 'flags and offset
        <FieldOffset(8)> Public ip_ttl As Byte 'Time To Live
        <FieldOffset(9)> Public ip_protocol As Byte 'protocol (TCP, UDP etc)
        <FieldOffset(10)> Public ip_checksum As Short 'IP Header checksum
        <FieldOffset(12)> Public ip_srcaddr As Long 'Source address
        <FieldOffset(16)> Public ip_destaddr As Long 'Destination Address
    End Structure

End Module

This goes into a class model:

Imports System.Net.Sockets
Imports System.Net

Public Class BaseSocket

    Protected len_receive_buf As Integer
    Protected len_send_buf As Integer
    Protected receive_buf() As Byte
    Protected send_buf() As Byte
    Protected socket As socket

    Public Sub BaseSocket()

        len_receive_buf = 4096
        len_send_buf = 4096
        ReDim receive_buf(len_receive_buf)
        ReDim send_buf(len_send_buf)

    End Sub

    Public Sub CreateAndBindSocket(ByVal ip As String)

        socket = New Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP)
        socket.Blocking = False
        socket.Bind(New IPEndPoint(IPAddress.Parse(ip), 0))

    End Sub

    Public Sub Shutdown()

        If IsNothing(socket) = False Then
            socket.Shutdown(SocketShutdown.Both)
            socket.Close()
            socket = Nothing
        End If

    End Sub

    Public Property LengthReceiveBuf()
        Get
            Return len_receive_buf
        End Get
        Set(ByVal len_receive_buf)
            Call lockr(receive_buf)
        End Set
    End Property

    Function lockr(ByVal buff)
        len_receive_buf = Len(receive_buf)
        ReDim receive_buf(len_receive_buf)
    End Function

    Public Property SendBuf()
        Get
            Return len_send_buf
        End Get
        Set(ByVal len_send_buf)
            locks(send_buf)
        End Set

    End Property

    Function locks(ByVal buff)
        len_send_buf = Len(send_buf)
        ReDim send_buf(len_send_buf)
    End Function

    Public Function SetSockoption() As Boolean

        Dim ret_value As Boolean = True

        socket.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.HeaderIncluded, 1)

        Dim I(4) As Byte

        I(0) = 1
        I(1) = 0
        I(2) = 0
        I(3) = 0

        Dim OUT(4) As Byte

        Const SIO_RCVALL As Integer = &H98000001

        Dim ret_code As Integer = socket.IOControl(SIO_RCVALL, I, OUT)
        ret_code = OUT(0) + OUT(1) + OUT(2) + OUT(3)

        If ret_code <> 0 Then
            ret_value = False
        Else
            ret_value = True
        End If

        SetSockoption = ret_value

    End Function

    Public Property SocketHandle()
        Get
            Return socket
        End Get
            Set(ByVal socket)
        End Set
    End Property

End Class

Brief explanation.

I'm using the module to define the packet structure which will be used
against the recieved packet.

The class to create a listening, non-blocking socket on the port and
setting/getting both input/output buffer lengths and values.
I'd love to spend more time on this, but I thought it be more appropriate if
you had the opportunity to look over this code
first and see if this is really what you want and whether or not you want to
move forward with it.
 .


Quote:

> Hi Liz, thanks for getting back,

> What I am trying to do is to somehow trap the moment that the email
> client starts downloading the email from the server and somehow have
> my program:

> 1) Be notified when the download starts
> 2) Read the stream for contact information (e.g. incoming email
> address)

> If I understand you correctly, I can read the server directly and
> simply leave the emails on the server without deleting them.
> This would not be my preferred solution as I am trying to keep what
> actually comes down to the client and what gets 'tagged' in my program
> in sync.
> I think the specifications for email do inlude some kind of unique
> message number (at least within one particular server), but I am
> trying to stay away frrom having to do something like that.

> I thing personal anti-virus/firewall software may do something
> similar, but I may be brking up the wrong tree

> Plz. excuse is this is a duplicate post, but I cannot seem to find my
> response to your first post-back.



> >> Does anyone have any suggestions on how to listen on Port 110 for POP3
> >> traffic.

> >> It seems simple enough in Outlook to monitor for incoming email, but
> >> my application may not want to rely on any one particular client.
> >> The idea here is to retrieve email traffic without regard to the email
> >> client software.

> >I'm really not understanding what you want to do; Outlook doesn't listen
on
> >port 110; it contacts mail servers which are listening on port 110, says
> >"hey, what you got for me on this account" and downloads whatever it's
got

> >> I understand you can use event sinks if you are running your own SMTP
> >> server, but this will not allways be the case.
> >> Maybe the underlying question is if two processes can use the same
> >> socket/port - i.e. The email client that does its regular business,
> >> and my dotnet app retrieveing some information as it travels down to
> >> the email client from the POP3 server.

> >again, it's not clear what you're tring to accomplish .. but I don't see
why
> >you could not build a service which contacts the email server at interval
X,
> >looks at the emails waiting and does whatever it is you want it to do; it
> >obviously does not need to delete the messages, so Outlook can still get
> >them per the usual routine

> >> Not having to buy/create your own email client, and simply using the
> >> existing one (and somehow its reading its stream) would be the
> >> preferred situation.



Fri, 12 Aug 2005 07:34:00 GMT  
 Using Sockets/Ports to listen for POP3 traffic
On Sun, 23 Feb 2003 15:34:00 -0800, "Richard T. Edwards"

Quote:

>Okay, RFC 791 defines, essentially, what nneds to be to done here.

>You need to create two  no-blocking sockets, set some properties for each
>and then monitor packate activity.

Hi Richard,

Holy moley, I didn;t expect that level of detailed response. I mean
appreciated - it's certainly beyond my current, modest, abiltities,
but I'll try chomping into it.

I do have a couple questions however:

Why 2 sockets? With pop3 wouldn't I be pointing at port 110 on the
POP3 server (within the vb program, and not including what the email
client does)

BTW, when I use TCPClient to connect from a simple vb.net program to
my POP3 server, I continually get:
'No Connection could be made because the target machine actively
refused it" - ErrorCode:10061

Plz excuse if these seem like sophomoric questions, I'm new to this
socket stuff.

Many thanks to those that have posted to this thread



Fri, 12 Aug 2005 08:03:14 GMT  
 Using Sockets/Ports to listen for POP3 traffic
pop3 does use port 110.  I also saw smtp.  Which works on port 25.  Which is
why I suggested two.

as for:

Quote:
> BTW, when I use TCPClient to connect from a simple vb.net program to
> my POP3 server, I continually get:
> 'No Connection could be made because the target machine actively
> refused it" - ErrorCode:10061

You'll get that if you've not got the server name correctly.

Try this:

Dim pop3client As TcpClient = New TcpClient("mail.attbi.com", 110)

If that gets refused, you've got another problem to deal with.

Quote:
> Plz excuse if these seem like sophomoric questions, I'm new to this
> socket stuff.

> Many thanks to those that have posted to this thread

Never feel this way, we all,  have been there. and as some viewers from MS
know, so have I.
Quote:

> On Sun, 23 Feb 2003 15:34:00 -0800, "Richard T. Edwards"

> >Okay, RFC 791 defines, essentially, what nneds to be to done here.

> >You need to create two  no-blocking sockets, set some properties for each
> >and then monitor packate activity.

> Hi Richard,

> Holy moley, I didn;t expect that level of detailed response. I mean
> appreciated - it's certainly beyond my current, modest, abiltities,
> but I'll try chomping into it.

> I do have a couple questions however:

> Why 2 sockets? With pop3 wouldn't I be pointing at port 110 on the
> POP3 server (within the vb program, and not including what the email
> client does)

> BTW, when I use TCPClient to connect from a simple vb.net program to
> my POP3 server, I continually get:
> 'No Connection could be made because the target machine actively
> refused it" - ErrorCode:10061

> Plz excuse if these seem like sophomoric questions, I'm new to this
> socket stuff.

> Many thanks to those that have posted to this thread



Fri, 12 Aug 2005 12:48:23 GMT  
 Using Sockets/Ports to listen for POP3 traffic
Hi Richard,

I just thought of another question you (or this thread) may know the
answer to.

Is it possible to have a dotnet program somehow notified when that
external (to the dotnet progrram) email client opens port 110 to do
its business?

Something like an event firing when an external program opens and uses
that socket?
Maybe something like periodically polling (or something similar) that
socket/port from the vb.net program.

Thanks again!



Sat, 13 Aug 2005 05:43:44 GMT  
 Using Sockets/Ports to listen for POP3 traffic
It just occured to me what an analogous situation would be.
I remember doing 'packet sniffing' on network cards, and we had to put
those cards into 'promiscuous' mode to to the packet sniffing.
My understing is that this would be pretty low on the network OSI
model, and I was wondering if socket programming had something similar
at a higher level.


Sat, 13 Aug 2005 05:58:56 GMT  
 Using Sockets/Ports to listen for POP3 traffic
Sock level is pretty much at the gut of it all short of hardware interrupt
routines the cards' bios might have.

Course, could could use assembly if you really wanted to go grass roots<G!>

The code I sent you creates a non-blocking raw socket. Essentially, the type
of functionality is built overtop of this.

Is all of what you're trying to do in house?

If it is, you might want to think about having your programs do essentially
what Zone Alarm does and poistion yourself at the card io level  become the
listening socket for both ports there and then pass the censored data back
and forth from client to server.

One more thought.  If you're running Exchange with owc as well.

And to be perfectly honest with you, if you 're really this serious about
creating these kinds of programs -- and you already admitted to this -- and
you lack the coding expertise, Microsoft has some of the finest technical
support people on the face of this planet.

My way of thinking, if you want it done right, go to them.


Quote:
> It just occured to me what an analogous situation would be.
> I remember doing 'packet sniffing' on network cards, and we had to put
> those cards into 'promiscuous' mode to to the packet sniffing.
> My understing is that this would be pretty low on the network OSI
> model, and I was wondering if socket programming had something similar
> at a higher level.



Sat, 13 Aug 2005 16:00:22 GMT  
 Using Sockets/Ports to listen for POP3 traffic

Correct me if I am wrong on this one. Maybe a proxy WOULD be the way
to go on this.

At least a proxy in this sense (for POP3):

My VB program would have a TCPListener. The email client
(Eudora/Outlook/whatever) would point at the IP address and port of my
VB program  with the TCPlistener (localhost in cases where the email
client and the VB program reside)
The VB program would also have a TCPClient, that would point at the IP
address and port of the  real POP3 server.
The stream from the TCPlistener would pass to the TCPClient
uninterrupted and unaltered. Information in the opposite direction
from the POP3 server would pass back through the TCPClient to the
TCPlistener, and end up at the client
I would simply  read that stream for the TO and  FROM tags. (Well
parse the streams - yuck)

Seems like it might work - We'll see how it plays in Peoria.

I think this is what Zane was talking about.

Thanks to all contributors

Quote:

>>1) Be notified when the download starts
>>2) Read the stream for contact information (e.g. incoming email
>>address)

>If you really must do that when the client downloads email then I don't think
>you have any choice but to have the client connect through a proxy server and
>monitor the flow of data.  Such a proxy is relatively simple to write in .net -
>and if you want components that will handle all email message
>parsing/construction you should take a look at my mail components:
>www.abderaware.com.

>--
>           Abderaware
>    Fine Components For .NET
>   Turn on, tune in, download.




Sun, 14 Aug 2005 07:55:45 GMT  
 Using Sockets/Ports to listen for POP3 traffic
To Contributors of this thread

I finally made a working model using the proxy idea.
For those that are interested, just email me and I will give you my
source.

Thanks again

Quote:

>Does anyone have any suggestions on how to listen on Port 110 for POP3
>traffic.

>It seems simple enough in Outlook to monitor for incoming email, but
>my application may not want to rely on any one particular client.
>The idea here is to retrieve email traffic without regard to the email
>client software.
>I understand you can use event sinks if you are running your own SMTP
>server, but this will not allways be the case.
>Maybe the underlying question is if two processes can use the same
>socket/port - i.e. The email client that does its regular business,
>and my dotnet app retrieveing some information as it travels down to
>the email client from the POP3 server.
>Not having to buy/create your own email client, and simply using the
>existing one (and somehow its reading its stream) would be the
>preferred situation.

>Any ideas/thoughts/concepts greatly appreciated.

>Thanks in advance



Sat, 20 Aug 2005 06:22:30 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. VB Port Listening ** Only listening not bound to a port

2. How to make winsock control listen on an used port

3. Finding and listening to ports used by other programs

4. Listen to a port(Using Winsock)

5. listening on same port using winsock

6. Q: How to Listen to Open Port using Winsock (TCP/IP)

7. Listen to port or port sniff...

8. Socket, listen, connect one client only!

9. How to Listen to a socket.

10. Socket, listen, connect one client only!

11. socket Listen - API

12. How to Listen to a socket.

 

 
Powered by phpBB® Forum Software