OK....I needed a quick solution to this problem and I found a free one
instead of coding it myself (although that's what I'd rather do).
To solve the issue of being on 2 seperate networks (each of which requires
you to use their own mail server and only one of which requires a
username/password) I used Sleepwalker's Free SMTP Proxy
(
http://thesleepwalker.com/software/). It's written in VB6 - but no
source code is available.
I placed it on the Bellsouth DSL office server and redirected Outlook's
mail server to it. This way, no matter what network they are actually on,
Bellsouth mail servers always see the emails coming from the office DSL.
I'd love to make an open source .Net version, and I have the beginnings of
some code that may be able to help, but I am unsure of how to create the
outgoing connections to Bellsouth, how to relay the data between the
sockets, and how to tell when the connections should be closed.
This code is from Network Programming in .Net and is for a multi-threaded
file transfer app. It may be a start for a multithreaded proxy server.
<CODE>
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Public Class Form1
Private alSockets As ArrayList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim IPHost As IPHostEntry
IPHost = Dns.GetHostEntry(Dns.GetHostName())
Label1.Text = "My IP address is " & IPHost.AddressList(0).ToString
alSockets = New ArrayList
Dim thdListener As New Thread(New ThreadStart(AddressOf
listenerThread))
thdListener.Start()
End Sub
Public Sub listenerThread()
Dim tcpListener As New TcpListener(IPAddress.Any, 80808)
Dim handlerSocket As Socket
Dim thdstHandler As ThreadStart
Dim thdHandler As Thread
tcpListener.Start()
Do
handlerSocket = tcpListener.AcceptSocket
If handlerSocket.Connected Then
lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString & "
connected.")
SyncLock (Me)
alSockets.Add(handlerSocket)
End SyncLock
thdstHandler = New ThreadStart(AddressOf handlerthread)
thdHandler = New Thread(thdstHandler)
thdHandler.Start()
End If
Loop
End Sub
Public Sub handlerThread()
'This function finds the last used socket and then retrieves the
stream from this socket.
'An array is allocated to the same size as the stream, and once the
stream is fully recieved,
'its contents are copied into this array.
Dim handlerSocket As Socket
handlerSocket = (alSockets(alSockets.Count - 1))
Dim networkStream As NetworkStream = New
NetworkStream(handlerSocket)
Dim blockSize As Int16 = 1024
Dim thisRead As Int16
Dim dataByte(blockSize) As Byte
SyncLock Me
'only 1 process can access the same file at any given time
Dim myfileStream As Stream
myfileStream = File.OpenWrite("c:\upload.txt")
While (True)
thisRead = networkStream.Read(dataByte, 0, blockSize)
myfileStream.Write(dataByte, 0, dataByte.Length)
If thisRead = 0 Then Exit While
End While
myfileStream.Close()
End SyncLock
lbConnections.Items.Add("File Written")
handlerSocket = Nothing
End Sub
End Class
</CODE>
While this code seems to do a straight read, write the file and cut the
connection, I'd need to open a new TCP connection to the Bellsouth mail
servers, relay the incoming info to the mail servers and know when the
incoming connection had been terminated by Outlook to be able to destroy
the handlerThread.