Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create CommuniGate Pro User Accounts from VB 2008 application

Posted on 2009-03-30
2
Medium Priority
?
459 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

598 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