?
Solved

Create CommuniGate Pro User Accounts from VB 2008 application

Posted on 2009-03-30
2
Medium Priority
?
452 Views
Last Modified: 2014-10-31
I'm trying to create a HelpDesk application in Visual Basic 2008 with user management functions including user creation for Active Directory, MySQL and (hopefully) CommuniGate Pro e-mail accounts.  I haven't started on any of these yet because I want to do my research first to make sure that all of this will be possible.  I've seen some code posts for the Active Directory part, and the MySQL piece should be easy enough.  The part I'm having trouble pinning down is the e-mail account creation.

From the research I've done so far, the only way I've found to connect to the CommuniGate server from my VB application is through a command-line interface using the TELNET command.  I'm still pretty new to programming in general, so I'm still not 100% certain how I'm going to do that exactly, but my bigger question is whether or not this is the most effective method of accomplishing the goal.

So, I suppose the reason I'm posting here is to find out if anyone out there has done anything similar, and if there are any suggestions on the best way to make this happen.  Thanks in advance for your assistance.
0
Comment
Question by:khufford19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
khufford19 earned 0 total points
ID: 24064772
After doing a lot of searching, I found a useful link on another EE thread that pointed me in the right direction.  Now I've come up with the following code.  This uses some user settings variables I setup in the project to help keep from hard-coding any login credentials into the program.  Additionally, this isn't "cleaned up" for final use, but this is what I threw together and tested just to see if I could get a connection to work.

This is only for the user creation, but the commands can be tweaked to create, delete, or modify users in a CommuniGate mail server, or any other mail server administration function.

Hope this is helpful to someone else out there looking for a way to automate user creation functions for a CommuniGate server.  Please feel free to ask if you have any questions about the details as it took me a lot of digging around to find this, and then a bit of effort to put it all into practice.
Imports System.Net.Sockets
Imports System.Text
 
Public Class CGServer
    Private TELNETCONN As New TcpClient("mail.mailserver.com", <portID>)
    Private TELNET As NetworkStream
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Message As String
        Dim Response As String
 
        If TELNETCONN.Connected Then
            TELNET = TELNETCONN.GetStream
            If TELNET.CanRead Then
                Message = GetResponse()
                Response = Microsoft.VisualBasic.Left(Message, 3)
                If Response <> "200" Then
                    MsgBox(Message)
                    CloseCon()
                    Exit Sub
                End If
                SendText("USER " & My.Settings.MailAdminUser.ToString & vbCrLf)
 
                Message = GetResponse()
                Response = Microsoft.VisualBasic.Left(Message, 3)
 
                If Response <> "300" Then
                    MsgBox(Message)
                    CloseCon()
                    Exit Sub
                End If
 
                SendText("PASS " & My.Settings.MailAdminPass.ToString & vbCrLf)
 
                Message = GetResponse()
                Response = Microsoft.VisualBasic.Left(Message, 3)
 
                If Response <> "200" Then
                    MsgBox(Message)
                    CloseCon()
                    Exit Sub
                End If
 
                SendText("CREATEACCOUNT " & NewUserName & vbCrLf)
 
                Message = GetResponse()
                Response = Microsoft.VisualBasic.Left(Message, 3)
 
                If Response <> "200" Then
                    MsgBox(Message)
                    CloseCon()
                    Exit Sub
                End If
 
                SendText("SETACCOUNTPASSWORD " & NewUserName & " PASSWORD " & TemporaryPassword & vbCrLf)
 
                Message = GetResponse()
                Response = Microsoft.VisualBasic.Left(Message, 3)
 
                If Response <> "200" Then
                    MsgBox(Message)
                    CloseCon()
                    Exit Sub
                End If
 
                TELNET.Close()
            Else
                MsgBox("Unable to connect")
            End If
        Else
            Debug.Print("Connection Failed")
        End If
 
        CloseCon()
 
    End Sub
 
    Private Sub SendText(ByVal strMsg As String)
        Dim sendBytes As [Byte]()
 
        If Not ExtendedASCIIEncode(strMsg, sendBytes) Then
            Err.Raise(vbObjectError + 1, "SendText", "Error converting the byte array.")
            Exit Sub
        End If
 
        TELNET.Write(sendBytes, 0, sendBytes.Length)
    End Sub
 
    Private Function ExtendedASCIIEncode(ByVal strMsg As String, ByRef arrByte() As Byte) As Boolean
        Dim i As Integer
 
        Try
            ReDim arrByte(strMsg.Length - 1)
            For i = 0 To strMsg.Length - 1
                arrByte(i) = CByte(Asc(strMsg.Substring(i, 1)))
            Next i
 
            ExtendedASCIIEncode = True
        Catch ex As Exception
            If i > 0 Then
                ReDim Preserve arrByte(i - 1)
            End If
            ExtendedASCIIEncode = False
        End Try
    End Function
 
    Private Function GetResponse() As String
        Dim Start As Double
        Dim Tmr As Double
        Dim bytes() As Byte
 
        Start = Now.TimeOfDay.TotalSeconds
 
        ReDim bytes(TELNETCONN.ReceiveBufferSize)
 
        While Not TELNET.DataAvailable
 
            Tmr = Now.TimeOfDay.TotalSeconds - Start
 
            Application.DoEvents()
 
            If Tmr > 60 Then
                GetResponse = "TIMEOUT!"
                Exit Function
            End If
        End While
 
        If TELNET.DataAvailable Then
            ' Returns the data received from the host to the console.
            TELNET.Read(bytes, 0, CInt(TELNETCONN.ReceiveBufferSize))
            GetResponse = Encoding.ASCII.GetString(bytes)
        Else
            GetResponse = "TIMEOUT!"
        End If
    End Function
 
    Private Sub CloseCon()
        If Not TELNETCONN Is Nothing Then
            TELNETCONN.Close()
        End If
        TELNETCONN = Nothing
    End Sub
End Class

Open in new window

0
 
LVL 2

Expert Comment

by:G_Hosa_Phat
ID: 40415812
Thank you for this post.  I'm working on tweaking a few things (including adding a test for whether or not the account exists), but this definitely gives me a jumping-off point, and seems to work great for a new project I'm working on so my IT Department can have a single application to register/deregister users.  Much appreciated.

I'm also working on creating a CommuniGate Pro class library for .NET that I can use for future implementations.  Of course, I've got a LOT of work to do as I've just started the project, but I hope that I can put together something really useful for any other CG users going forward.
0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question