If anybody is curious about how to write a POP3 server in VB6, I'm making available my program Groupserver POP3. You can download the binaries or the source code here: http://serva.scieron.com/index.html
Here's a screenshot:
Enjoy!
-Mike
Last edited by half_eaten; Jan 25th, 2005 at 03:46 PM.
i haven't set up any accounts. I may move it to my w2k workststion.
seems like hard to read code, not following standards. you should clean it up some it'd be easier to debug and follow.
i haven't set up any accounts. I may move it to my w2k workststion.
seems like hard to read code, not following standards. you should clean it up some it'd be easier to debug and follow.
Erm yeah... hehe I'm pretty lazy. I'll go through and make it easier to follow.
Thanks for checking it out though, when you really get a chance to test it out let me know what you think. I want to add an SMTP server too and make it a full-blown complete e-mail server.
i haven't set up any accounts. I may move it to my w2k workststion.
seems like hard to read code, not following standards. you should clean it up some it'd be easier to debug and follow.
I get an error, 'Address in use' I might be running something else, i'll have a look,
EDIT: the binaries and source code have been updated on my site to include the App.Path and it has an error handling routing in case port 110 is in use.
-Mike
Last edited by half_eaten; Jan 25th, 2005 at 04:44 PM.
FreeFile is a function that returns the next available file number so as to ensure that the same number is not being used for more than one file. Here's an example of its use
VB Code:
Dim FileNum As Integer
' Get the next available file number.
FileNum = FreeFile
' Open a file using the file number
Open "MYFILE.FIL" For Random As FileNum Len = RecLength
half_eaten, would you like this thread moved to the CodeBank. Or maybe better would be to wait until you made whatever improvements you wanted to make and then post a new thread there.
I am almost done with an ActiveX control version of the POP3 server engine in case anybody needs a POP3 server in their own programs. It's designed to be as simple as possible to use. Here some examples of code you would use to work with it. The control's name is SvrPOP3.
SvrPOP3.InitServer - Starts server SvrPOP3.AddNewUser (UserName as string) - Adds a new user (duh) SvrPOP3.DeleteUser (UserName as string) - Delete a user SvrPOP3.ComposeMail (FromUser, ToUser, Subject, DateTime, MessageBody) - Put an e-mail in a user's account
etc......
I should be all done with that some time early tomorrow or later tonight. If anybody's interested, I'll post it here!
Okay people, here it is... the ActiveX version of the my POP3 server engine! If you need a POP3 server in your application, give this a shot... I attached the zip file of the OCX and a readme.txt file with instructions to this post!
It will ask you to register. [Edited by MartinLiss]
when you use the "Register" method, the registration name you should put in is "temp" and the registration code is "116101109112" the registration name is case-sensitive so make sure it's "temp" is in lowercase!!
who said it doesn't change? it depends on the registration name. i have a little program i wrote to generate it. don't worry its a decent registration routine... ill post the ocx code tonight too
Wow...nice.
Cheers for posting your code here. Much appreciated.
Once I have jigged your code a little I will see if it works.
You failed to add "Option Explicit" at the top of your code.
If you add this then you MUST declare a varible, ie:
You have:
Code:
Private Sub Woof()
MyMsg = "Growl"
MsgBox MyMsg
End Sub
With Option Explicit you above code will error on the MyMsg = line.
You would have to do:
Code:
Private Sub Woof()
Dim MyMsg As String
MyMsg = "Growl"
MsgBox MyMsg
End Sub
You do this to avoid the following mistakes:
Code:
Private Sub Woof()
MyMsg = "Growl"
MyMsg = MyMsg & "Moose"
MyMsg = NyMsg & "Fish" 'bad coding mistake here
MsgBox MyMsg
End Sub
You have mispelt MyMsg as NyMsg. This could, and most likely to, cause your app to crash/not work.
If you app does work, then top notch, I will be impressed you managed to iron out all bugs without option explicit
Also, I think I may have worked out why it fails on Port 110.
You are using winsock right. That's the sort of control that I would like to close gracefully, and shut it down properly. This way you know ports are closed correctly etc
Your following code is, I would say, EVIL!
Code:
Private Sub itmExit_Click()
res = MsgBox("If you close this program, the mail server will not function. Are you sure?", vbYesNo, "Postmaster")
If res = vbNo Then Exit Sub
End
End Sub
WHich you call from the Form_Unload event and from the menu exit event.
It's the End command that is the problem here. As soon as your app sees this it terminates itself, and all it's objects. No Unload events get fired, no connects get closed. It can cause all sorts of wonderful and wierd things to happen. Some people like to use it as a last resort, but only after then have close things down 1st.
That code should be:
Code:
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("If you close this program, the mail server will not function. Are you sure?", vbYesNo, "Postmaster") = vbYes Then
'Code here to close winsock
Else
Cancel = True
End If
End Sub
Private Sub itmExit_Click()
Unload Me
End Sub
That will unload your application gracefully, all objects closed properly blah blah blah.
A few other small points:
Gotos, there's no need to use them in VB, they just cause unmanagable code (except error handlers)
Code indentation, makes it MUCH MUCH easier to follow blocks of code.
Varible naming, hungarian notation?
Using constants, or more modular level varibles
FreeFile thing that was mentioned above.
Hahaha...Gotos that goto an actual "line number"
I haven't seen that in about 10 years.
Something you definately don't see every day
If you need help with anything, or have any questions on anything we've mentioned, then just give us a shout.
One thing I did notice was you had 45 winsock controls on your form.
You can dynamically create and destroy these at runtime. You can also use one winsock array to do everything, currently you have 1 array, and a seperate listening one, but this isn't a massive problem, just a little more code.
Code:
Option Explicit
Private Sub POP_Close(Index As Integer)
Unload POP(Index)
End Sub
Private Sub POP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim lngNewIndex As Long
If Index = 0 Then
lngNewIndex = GetNextIndex
Load POP(lngNewIndex)
POP(lngNewIndex).Accept requestID
End If
End Sub
Private Function GetNextIndex() AS Long
Dim lngIndex As Long
On Error Goto ErrHandler
For lngIndex = 1 To POP.UBound
lngNewIndex = POP(lngIndex).Index
Next lngIndex
ErrHandler:
GetNextIndex = lngIndex
Exit Function
Something like that anyways.
Does that make sense?
When your form loads you get POP(0) to start listening for connections.
WOka
Last edited by Wokawidget; Jan 26th, 2005 at 09:27 PM.
I hope you don't think I am having a go at you, or your code, here. I am merely pointing out ways to can improve it for your own benefit. You'll see the difference on how easy it is to add more functionality to it, with minimal code.
One other point.
Doing:
Code:
Private Sub ListMsgs(idx)
Where you do not declare the parameter, or declare any varibles in functions, it means that it is a variant. These take up considerable more memory, plus are slower to deal with. Using the odd one in a place where it has a purpose is OK, but declaring all your varibles throughout your entire app maybe a little dodgy.
No, I know you're not having a go at me.. I appreciate the pointers. I first started messing around for fun in GWBASIC when I was 6. I'm 20 now...
About me using line number... yeah, I was raised on QuickBasic
Still haven't lost all my old QB habits...
When I was 13 I wrote a fully functional multi-node(16 nodes to be exact) BBS program in QuickBasic. I'm still proud of that, ended up with ~29,000 lines of QB code. It would show a static main screen showing what users are online and what they're doing while executing each node's events separately in the background, and if you wanted you could choose a node and it would show what they're seeing on their screen. Even had a multi-user chat room. Not trying to toot my own horn or anything, but I'm still more proud of that than anything else I've done really.
I wish the damn floppy disk with the code didn't get full of data errors. Wish they had CD burners back then!
Anyway more to the point, I'll go through and clean up my code and take a couple of your pointers.. I really threw it together in a hurry. I'm bad about that!!
Btw, I do know about the variant thing... that falls under the category of me being lazy.
THANKS for the tips!! It's appreciated.
-Mike
QB didn't require line numbers, and I used them only as a last resort. Actually, I only used Line Labels, and that was sparingly, like for error routines. I used a couple of goto's also. I have a 6000 line program before I started getting out of memory errors. I quit development at that point.
QB didn't require line numbers, and I used them only as a last resort. Actually, I only used Line Labels, and that was sparingly, like for error routines. I used a couple of goto's also. I have a 6000 line program before I started getting out of memory errors. I quit development at that point.
Yeah I didn't use them on every line, but I used them frequently say, when I had a line or two of code that was to accessed from multiple places in the code... I have some bad programming habits.
And you think this POP3 server code is disorganized? You should've seen my BBS code!!
I was going to add a few more features to that thing too, but when I got near 30,000 lines it told me it didn't have memory for any more code. LOL!
My question was aimed at half_eaten, they said they were going to chamge their code.
I wouldn't help you anyways Hehe
Woof
I haven't started yet... I'll have it done tonight and I'll post the new code... I was also going to clean up the code and make it easier to read. Thanks for the help!!
I was going to have a go at an SMTP server soon also. That's going to be a little tougher!