.Net

Tim

.Net

Postby Tim » Thu Jul 08, 2004 3:04 am

OK, for those of you that are looking for it, a simple way to manage MailEnable from .Net

A few disclaimers (in no particular order):

It was made to my specs, so each postoffice needs to be set up so that postoffice name = domain name and 1 domain per postoffice.
In otherwords postoffice name = domain.ext, with one domain (name = domain.ext)
This isn't the way MailEnable recommends to do it, but it is a simple way to do it if you allow your users to administer there own domains.

Also, at the top of the vb codebehind for the control (see below) is a string variable called DomainName. You will need to set this onPageLoad to the correct domain. (I'm going to strip it from the url used to access the page after authentication)

You will need to recreate some stuff (references, classes, etc., I'm just posting the code), see below for some instructions and tips.

The identity you are running your web app as needs rights to Mail Enable\Config and Mail Enable\Postoffices.

Make sure you Rename the DEFAULT.MAI message in Mail Enable\Config\Postoffices and in existing postoffice directories below that if you don't want the default mail message.

This code has been tested, but don't use it on a production server until you are sure it works the way you want.

The class uses an xml config file (see below for more info) for keeping track of some additional stuff (and simplify things, and so as not to rely to heavily on COM objects), you will have to manually make it for existing domains, and make sure existing domains follow the one-to-one postoffice to domain rule (see above)

I didn't plan on sharing this, it was a quick job, and I started just by fooling around, so there are some redundancies, poor naming conventions, very little commenting, etc., it is what it is.

If you improve on it, or find a bug, post here to let me know, or email me at tpkling at yahoo.com.


Some instructions:

This is the blank config file:

Code: Select all

<?xml version="1.0" ?>
<domain>
<name />
<boxes>5</boxes>
<redirects>10</redirects>
<filters>10</filters>
<limit>10240</limit>
<catchall />
</domain>

Place it in the Mail Enable\Config\Postoffices dir (as "config.xml"), it will be copied to new domains the first time they are accessed.
You'll see what the values do if you successfully run the page.
"mailbox" nodes are added to this file as mailboxes are created, if you need to recreate this for an existing domain, experiment on a new domain and you will see how they work.
Domain config files are stored as "Mail Enable\Config\Postoffices\domain.ext\config.xml".

Next, create a blank solution.

Two projects will be added to it:
One is a class library, mine is called "SWMail", you can call it whatever you want, but you will need to change some code if you change the name.
The second is a Web App, mine is called "SWMailDev", this one doesn't really matter what you call it.

The class library is what does the ditry work. You will need to add two new items (classes) to it (Domain.vb and Validator.vb). Reference MEAOPO.dll, MEAOAM.dll, and MEAOAU.dll in this project!



Validator.vb Source:

Code: Select all

Imports System.Text.RegularExpressions

Public Class Validator
    Dim _Valid As Boolean
    Dim _Type As ValidateType.ValidateFor
    Dim _Err As String
    Public ReadOnly Property IsValid() As Boolean
        Get
            Return _Valid
        End Get
    End Property
    Public ReadOnly Property ErrorMessage() As String
        Get
            Return _Err
        End Get
    End Property
    Public Sub New(ByVal ValidatorType As ValidateType.ValidateFor)
        _Valid = False
        _Type = ValidatorType
    End Sub
    Public Sub Validate(ByVal s As String)
        Select Case _Type
            Case ValidateType.ValidateFor.Address
                Dim m As Match = Regex.Match(s, "^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$")
                If m.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Invalid email format."
                End If
            Case ValidateType.ValidateFor.AddressName
                Dim m As Match = Regex.Match(s, "[A-Za-z0-9][A-Za-z0-9\.\-_]{0,30}[A-Za-z0-9]")
                Dim m2 As Match = Regex.Match(s, "[A-Za-z0-9]")
                If m.ToString = s Or m2.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Addresses need to be at least one letter or digit,<br>and can only contain letters, numbers, or the charcters:  period (.), dash (-), or underscore (_).<br>They can only have a maximum of 32 charcters."
                End If
            Case Else
                _Err = "Error:  Wrong number of arguments or wrong validator type."
        End Select
    End Sub
    Public Sub Validate(ByVal s As String, ByVal c As String)
        If _Type = ValidateType.ValidateFor.Password Then
            If s = c Then
                Dim m As Match = Regex.Match(s, "[0-9A-Za-z]{6,20}")
                If m.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Passwords should only contain 6-20 letters and/or numbers."
                End If
            Else
                _Err = "Passwords do not match, try again."
            End If
        Else
            _Err = "Error:  Wrong number of arguments or wrong validator type."
        End If
    End Sub
    Public Class ValidateType
        <FlagsAttribute()> _
        Enum ValidateFor
            Address = 1
            AddressName = 2
            Password = 4
        End Enum

    End Class
End Class



Domain.vb is more complex and includes several classes:

Code: Select all


Imports System.Xml
Imports System.IO


Public Class Domain

#Region " Private Members "

    Private Const MEPath As String = "C:\Program Files\Mail Enable\Config" 'path in mailenable class of mailbox class is independent of this
    Private _ConfigPath As String
    Private _Xml As XmlNode
    Private _Limit As Integer
    Private Mailboxes As Mailbox()

#End Region

#Region " Public Properties "

    Public ReadOnly Property Name() As String
        Get
            Return _Xml.SelectSingleNode("name").InnerText
        End Get
    End Property

    Public ReadOnly Property CountFilters() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Filter & """]").Count
        End Get
    End Property

    Public ReadOnly Property CountRedirects() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Redirect & """]").Count
        End Get
    End Property

    Public ReadOnly Property CountBoxes() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Box & """]").Count + _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.DropForward & """]").Count
        End Get
    End Property

    Public ReadOnly Property MaxBoxes() As Integer
        Get
            Return _Xml.SelectSingleNode("boxes").InnerText
        End Get
    End Property

    Public ReadOnly Property MaxRedirects() As Integer
        Get
            Return _Xml.SelectSingleNode("redirects").InnerText
        End Get
    End Property

    Public ReadOnly Property MaxFilters() As Integer
        Get
            Return _Xml.SelectSingleNode("filters").InnerText
        End Get
    End Property

    Public Property Catchall() As String
        Get
            Return _Xml.SelectSingleNode("catchall").InnerText.Trim
        End Get
        Set(ByVal Value As String)
            Try
                If _Xml.SelectSingleNode("catchall").InnerText.Trim = "" Then
                    Dim meInterface As New Mailbox.MailEnable(Me.Name)
                    meInterface.EnableCatchall(Value)
                Else
                    If Value = "" Then
                        Dim meInterface As New Mailbox.MailEnable(Me.Name)
                        meInterface.DisableCatchall(_Xml.SelectSingleNode("catchall").InnerText.Trim)
                    Else
                        Dim meInterface As New Mailbox.MailEnable(Me.Name)
                        meInterface.EditCatchall(_Xml.SelectSingleNode("catchall").InnerText.Trim, Value)
                    End If
                End If
                _Xml.SelectSingleNode("catchall").InnerText = Value
                SaveXMLOnly()
            Catch ex As Exception
                'something went wrong
            End Try
        End Set
    End Property

    Public ReadOnly Property CatchallEnabled() As Boolean
        Get
            If _Xml.SelectSingleNode("catchall").InnerText.Trim = "" Then
                Return False
            Else
                Return True
            End If
        End Get
    End Property

#End Region

#Region " Public Constructor "

    Public Sub New(ByVal domain As String)
        _ConfigPath = MEPath & "\Postoffices\" & domain & "\config.xml"
        If Not File.Exists(_ConfigPath) Then
            Dim tempdoc As New XmlDocument
            tempdoc.Load(MEPath & "\Postoffices\config.xml")
            tempdoc.DocumentElement.SelectSingleNode("name").InnerText = domain
            tempdoc.Save(_ConfigPath)
        End If
        Dim doc As New XmlDocument
        doc.Load(_ConfigPath)
        _Xml = doc.DocumentElement
        _Limit = _Xml.SelectSingleNode("limit").InnerText.Trim

        Dim i As Integer = -1
        ReDim Mailboxes(_Xml.SelectNodes("mailbox").Count - 1)
        For Each mb As XmlNode In _Xml.SelectNodes("mailbox")
            i += 1
            Mailboxes(i) = New Mailbox(domain, mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            Mailboxes(i).Xml = mb
        Next
    End Sub

#End Region

#Region " Public Methods "

    Public Function NewRedirect(ByVal name As String, ByVal toaddr As String) As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Redirect, toaddr)
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function NewFilter(ByVal name As String) As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Filter)
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function NewMailbox(ByVal name As String, ByVal password As String, Optional ByVal forward As String = "") As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                If forward = "" Then
                    m.Add(Mailbox.MailboxType.Types.Box, password)
                Else
                    m.Add(Mailbox.MailboxType.Types.DropForward, password, forward)
                End If
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function EditRedirect(ByVal oldname As String, ByVal name As String, ByVal forward As String) As Boolean
        Try
            Dim existsCheck As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            If existsCheck Is Nothing Or oldname = name Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Redirect, forward)
                Dim bFound As Boolean = False
                For Each mb As Mailbox In Mailboxes
                    If mb.Name = oldname Then
                        mb.Read(m.Xml)
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then
                    Dim MEResult As Boolean = False
                    If Me.Catchall = oldname Then
                        Me.Catchall = ""
                        MEResult = m.Edit(oldname)
                        Me.Catchall = name
                    Else
                        MEResult = m.Edit(oldname)
                    End If
                    If MEResult Then
                        If Save() Then Return Sort()
                    End If
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function EditMailbox(ByVal oldname As String, ByVal name As String, ByVal password As String, Optional ByVal forward As String = "") As Boolean
        Try
            Dim existsCheck As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            If existsCheck Is Nothing Or oldname = name Then
                Dim editNode As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & oldname & """]")
                If password = "" Then password = editNode.SelectSingleNode("password").InnerText
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                If forward = "" Then
                    m.Add(Mailbox.MailboxType.Types.Box, password)
                Else
                    m.Add(Mailbox.MailboxType.Types.DropForward, password, forward)
                End If
                Dim bFound As Boolean = False
                For Each mb As Mailbox In Mailboxes
                    If mb.Name = oldname Then
                        mb.Read(m.Xml)
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then
                    Dim MEResult As Boolean = False
                    If Me.Catchall = oldname Then
                        Me.Catchall = ""
                        MEResult = m.Edit(oldname)
                        Me.Catchall = name
                    Else
                        MEResult = m.Edit(oldname)
                    End If
                    If MEResult Then
                        If Save() Then Return Sort()
                    End If
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function DeleteMailbox(ByVal name As String) As Boolean
        Try
            Dim Result As Boolean = False
            For Each mb As Mailbox In Mailboxes
                If mb.Name = name Then
                    If mb.Delete() Then
                        Dim deleteNode As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
                        _Xml.RemoveChild(deleteNode)
                        If _Xml.SelectSingleNode("catchall").InnerText = name Then _Xml.SelectSingleNode("catchall").InnerText = ""
                        Result = SaveXMLOnly()
                    End If
                    Exit For
                End If
            Next
            Return Result
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function GetMailboxes(Optional ByVal name As String = "") As Mailbox()
        Dim sSearch As String = "mailbox[(@type=""" & Mailbox.MailboxType.Types.Box & """ or @type=""" & Mailbox.MailboxType.Types.DropForward & """)"
        If name <> "" Then sSearch &= " and @name=""" & name & """"
        sSearch &= "]"
        Return GenericGet(sSearch)
    End Function

    Public Function GetRedirects(Optional ByVal name As String = "") As Mailbox()
        Dim sSearch As String = "mailbox[@type=""" & Mailbox.MailboxType.Types.Redirect & """"
        If name <> "" Then sSearch &= " and @name=""" & name & """"
        sSearch &= "]"
        Return GenericGet(sSearch)
    End Function

    Public Function GetEnabled() As Mailbox()
        Return GenericGet("mailbox[@type=""" & Mailbox.MailboxType.Types.Box & """ or @type=""" & Mailbox.MailboxType.Types.DropForward & """ or @type=""" & Mailbox.MailboxType.Types.Redirect & """]")
    End Function

    Public Function GetFilters() As Mailbox()
        Return GenericGet("mailbox[@type=""" & Mailbox.MailboxType.Types.Filter & """]")
    End Function

#End Region

#Region " Private Functions "

    Private Function GenericGet(ByVal xpathSearch As String) As Mailbox()
        Dim resultslist As XmlNodeList = _Xml.SelectNodes(xpathSearch)
        Dim results As Mailbox()
        ReDim results(resultslist.Count - 1)
        Dim i As Integer = -1
        For Each mb As XmlNode In resultslist
            i += 1
            results(i) = New Mailbox("", mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            results(i).Read(mb)
        Next
        Return results
    End Function

    Private Function SaveXMLOnly() As Boolean
        Try
            Dim doc As New XmlDocument
            doc.LoadXml(_Xml.OuterXml)
            doc.Save(_ConfigPath)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function Save() As Boolean
        Try
            Dim doc As New XmlDocument
            doc.LoadXml(_Xml.OuterXml)
            For Each mbn As XmlNode In doc.DocumentElement.SelectNodes("mailbox")
                doc.DocumentElement.RemoveChild(mbn)
            Next
            For Each mb As Mailbox In Mailboxes
                Dim newNode As XmlNode = doc.ImportNode(mb.Xml, True)
                doc.DocumentElement.AppendChild(newNode)
            Next
            _Xml = doc.DocumentElement
            doc.Save(_ConfigPath)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function Sort() As Boolean
        Dim i As Integer = -1
        ReDim Mailboxes(_Xml.SelectNodes("mailbox").Count - 1)
        Dim mbList As XmlNodeList = _Xml.SelectNodes("mailbox")
        Dim mbnames As New ArrayList
        For j As Integer = 0 To mbList.Count - 1
            mbnames.Add(mbList.Item(j).Attributes.GetNamedItem("name").InnerText)
        Next
        mbnames.Sort()
        For Each name As String In mbnames
            i += 1
            Dim mb As XmlNode
            mb = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            Mailboxes(i) = New Mailbox(_Xml.SelectSingleNode("name").InnerText, mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            Mailboxes(i).Xml = mb
        Next
        Return Save()
    End Function

#End Region



#Region " Mailbox Class "

    Public Class Mailbox

#Region " Private Members "

        Dim _Postoffice As String
        Dim _Mailbox As String
        Dim _Limit As Integer
        Dim _Password As String
        Dim _RedirectAddress As String
        Dim _RedirectStatus As Integer '0 = no, 1 = forward, 2 = drop and forward
        Dim _Status As Integer ' 0=disabled. 1=enabled
        Dim _Xml As XmlNode

#End Region

#Region " Public Properties "

        Public Property Xml() As XmlNode
            Get
                Return _Xml
            End Get
            Set(ByVal Value As XmlNode)
                _Xml = Value
            End Set
        End Property

        Public ReadOnly Property Name() As String
            Get
                Return _Mailbox
            End Get
        End Property

        Public ReadOnly Property Redirected() As String
            Get
                If _RedirectStatus = 0 Then
                    Return False
                Else
                    Return True
                End If
            End Get
        End Property

        Public Property Password() As String
            Get
                Return _Password
            End Get
            Set(ByVal Value As String)
                _Password = Value
                _Xml.SelectSingleNode("password").InnerText = Value
            End Set
        End Property

        Public ReadOnly Property Redirect() As String
            Get
                Return _RedirectAddress
            End Get
        End Property

        Public ReadOnly Property RedirectHTML() As String
            Get
                If _RedirectAddress <> "" Then
                    Return _RedirectAddress
                Else
                    Return "&nbsp;"
                End If
            End Get
        End Property

#End Region

#Region " Public Constructor "

        Public Sub New(ByVal domain As String, ByVal name As String, ByVal limit As Integer)
            _Postoffice = domain
            _Mailbox = name
            _Limit = limit
        End Sub

#End Region

#Region " Public Methods "

        Public Function Add(ByVal t As MailboxType.Types, Optional ByVal sExtraInfo As String = "", Optional ByVal sExtraInfo2 As String = "") As Boolean
            Dim txml As New XmlDocument
            txml.LoadXml("<mailbox type=""0"" name=""" & _Mailbox & """><password /><redirect /></mailbox>")
            txml.DocumentElement.SetAttribute("type", t)
            Select Case t
                Case MailboxType.Types.Box
                    _Password = sExtraInfo
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("password").InnerText = sExtraInfo
                Case MailboxType.Types.Redirect
                    _Password = "password"
                    _RedirectAddress = sExtraInfo
                    _RedirectStatus = 1
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("redirect").InnerText = sExtraInfo
                Case MailboxType.Types.DropForward
                    _Password = sExtraInfo
                    _RedirectAddress = sExtraInfo2
                    _RedirectStatus = 2
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("password").InnerText = sExtraInfo
                    txml.DocumentElement.SelectSingleNode("redirect").InnerText = sExtraInfo2
                Case MailboxType.Types.Filter
                    _Password = "password"
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 0
            End Select
            _Xml = txml.DocumentElement
            Return True
        End Function

        Public Sub Read(ByVal xml As XmlNode)
            Dim t As MailboxType.Types = xml.Attributes.GetNamedItem("type").InnerText
            Select Case t
                Case MailboxType.Types.Box
                    _Password = xml.SelectSingleNode("password").InnerText
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 1
                Case MailboxType.Types.Redirect
                    _Password = "password"
                    _RedirectAddress = xml.SelectSingleNode("redirect").InnerText
                    _RedirectStatus = 1
                    _Status = 1
                Case MailboxType.Types.DropForward
                    _Password = xml.SelectSingleNode("password").InnerText
                    _RedirectAddress = xml.SelectSingleNode("redirect").InnerText
                    _RedirectStatus = 2
                    _Status = 1
                Case MailboxType.Types.Filter
                    _Password = "password"
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 0
            End Select
            _Xml = xml
        End Sub

        Public Function Delete() As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.Delete(Me)
        End Function

        Public Function Save() As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.SaveNew(Me)
        End Function

        Public Function Edit(ByVal OldName As String) As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.SaveEdit(Me, OldName)
        End Function

#End Region


#Region " MailboxType Enum "

        Public Class MailboxType
            <FlagsAttribute()> _
            Enum Types
                Box = 1
                Redirect = 2
                DropForward = 3
                Filter = 4
            End Enum
        End Class

#End Region

#Region " MailEnable Class "

        Public Class MailEnable

#Region " Private Members "

            Dim _Domain As String
            Private Const MEPath As String = "C:\Program Files\Mail Enable\Postoffices"

#End Region

#Region " Public Constructor "

            Public Sub New(Optional ByVal sDomain As String = "")
                _Domain = sDomain
            End Sub

#End Region

#Region " Public Methods "

            Public Sub EditCatchall(ByVal OldMailbox As String, ByVal Mailbox As String)
                DisableCatchall(OldMailbox)
                EnableCatchall(Mailbox)
            End Sub

            Public Sub EnableCatchall(ByVal Mailbox As String)
                Dim AddressMap As New MEAOAM.AddressMap
                With AddressMap
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:*@" & _Domain & "]"
                    .AddAddressMap()
                End With
            End Sub

            Public Sub DisableCatchall(ByVal Mailbox As String)
                Dim AddressMap As New MEAOAM.AddressMap
                With AddressMap
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:*@" & _Domain & "]"
                    If .GetAddressMap = 1 And .SourceAddress = "[SMTP:*@" & _Domain & "]" Then
                        .EditAddressMap(_Domain, "[SMTP:swstempcatchall@" & _Domain & "]", "[SF:" & _Domain & "/" & Mailbox & "]", "")
                    End If
                End With
                'this is lame...
                Dim AddressMap2 As New MEAOAM.AddressMap
                With AddressMap2
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:swstempcatchall@" & _Domain & "]"
                    If .GetAddressMap = 1 Then
                        .RemoveAddressMap()
                    End If
                End With
            End Sub

            Public Function SaveNew(ByRef parent As Mailbox) As Boolean

                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = parent._Mailbox
                    .Limit = parent._Limit
                    .RedirectAddress = "[SMTP:" & parent._RedirectAddress & "]"
                    .RedirectStatus = parent._RedirectStatus
                    .Status = parent._Status
                End With
                If MEMailbox.AddMailbox = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .Description = ""
                    .Password = parent._Password
                    .Rights = "USER"
                    .Status = parent._Status
                    .UserName = parent._Mailbox & "@" & parent._Postoffice
                End With
                If MELogin.AddLogin = 0 Then Return False

                Dim sDir As String = MEPath & "\" & parent._Postoffice
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "\mailroot"
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "\" & parent._Mailbox
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "\inbox"
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:" & parent._Mailbox & "@" & parent._Postoffice & "]"
                End With
                If MEAddressMap.AddAddressMap = 0 Then Return False

                Return True

            End Function

            Public Function SaveEdit(ByRef parent As Mailbox, ByVal oldname As String) As Boolean
                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = oldname
                    .Limit = -1
                    .RedirectAddress = ""
                    .RedirectStatus = -1
                    .Status = -1
                End With
                '               If MEMailbox.GetMailbox = 0 Then Return False
                If MEMailbox.EditMailbox(parent._Postoffice, parent._Mailbox, "[SMTP:" & parent._RedirectAddress & "]", parent._RedirectStatus, parent._Status, parent._Limit, MEMailbox.Size) = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .Description = ""
                    .Password = ""
                    .Rights = "USER"
                    .Status = -1
                    .UserName = oldname & "@" & parent._Postoffice
                End With
                '                If MELogin.GetLogin = 0 Then Return False
                If MELogin.EditLogin(parent._Mailbox & "@" & parent._Postoffice, parent._Status, parent._Password, parent._Postoffice, MELogin.Description, MELogin.LoginAttempts, MELogin.LastAttempt, MELogin.LastSuccessfulLogin, "USER") = 0 Then Return False

                If oldname <> parent._Mailbox Then
                    Dim sDir As String = MEPath & "\" & parent._Postoffice
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    sDir &= "\mailroot"
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    Dim sNewDir As String = sDir & "\" & parent._Mailbox
                    sDir &= "\" & oldname
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    Directory.Move(sDir, sNewDir)
                    sNewDir &= "\inbox"
                    If Not Directory.Exists(sNewDir) Then Directory.CreateDirectory(sNewDir)
                End If

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & oldname & "]"
                    .Scope = ""
                    .SourceAddress = ""
                End With
                If MEAddressMap.EditAddressMap(parent._Postoffice, "[SMTP:" & parent._Mailbox & "@" & parent._Postoffice & "]", "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]", MEAddressMap.Scope) = 0 Then Return False

                Return True

            End Function

            Public Function Delete(ByRef parent As Mailbox, Optional ByVal RemoveDirectory As Boolean = True) As Boolean

                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = parent._Mailbox
                    .Limit = -1
                    .RedirectAddress = ""
                    .RedirectStatus = -1
                    .Status = -1
                End With
                If MEMailbox.RemoveMailbox = 0 Then Return False

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = ""
                End With
                If MEAddressMap.RemoveAddressMap = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .LastAttempt = -1
                    .LastSuccessfulLogin = -1
                    .LoginAttempts = -1
                    .Password = ""
                    .Rights = ""
                    .Status = -1
                    .UserName = parent._Mailbox & "@" & parent._Postoffice
                End With
                If MELogin.RemoveLogin = 0 Then Return False

                If RemoveDirectory Then
                    Dim sDir As String = MEPath & "\" & parent._Postoffice & "\mailroot\" & parent._Mailbox
                    If Directory.Exists(sDir) Then Directory.Delete(sDir, True)
                End If

                Return True

            End Function

#End Region

        End Class 'MailEnable

#End Region

    End Class 'Mailbox

#End Region

End Class ' Domain








In the Web App Project, reference your Class library (SWMail).

Now, in the web app project we are going to create a new user control.
Call it "EmailApp.ascx"
Heres the code behind:(EmailApp.ascx.vb)
[code]

Public Class EmailApp
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents litErrorMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlError As System.Web.UI.WebControls.Panel
Protected WithEvents litWarningMessage As System.Web.UI.WebControls.Literal
Protected WithEvents hlContinue As System.Web.UI.WebControls.HyperLink
Protected WithEvents pnlWarning As System.Web.UI.WebControls.Panel
Protected WithEvents litSuccessMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlSuccess As System.Web.UI.WebControls.Panel
Protected WithEvents litHelpMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlHelp As System.Web.UI.WebControls.Panel
Protected WithEvents lblCountBoxes As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxBoxes As System.Web.UI.WebControls.Label
Protected WithEvents btnNewEmail As System.Web.UI.WebControls.LinkButton
Protected WithEvents litMailboxList As System.Web.UI.WebControls.Literal
Protected WithEvents lbHelpRedirect As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblCountRedirects As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxRedirects As System.Web.UI.WebControls.Label
Protected WithEvents lbNewRedirect As System.Web.UI.WebControls.LinkButton
Protected WithEvents litRedirectList As System.Web.UI.WebControls.Literal
Protected WithEvents pnlDefault As System.Web.UI.WebControls.Panel
Protected WithEvents lblEmailAction As System.Web.UI.WebControls.Label
Protected WithEvents btnCancelEmail As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain1 As System.Web.UI.WebControls.Literal
Protected WithEvents tbPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents lblLeaveBlank As System.Web.UI.WebControls.Label
Protected WithEvents tbConfirmPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDoNewEmail As System.Web.UI.WebControls.Button
Protected WithEvents btnDoSaveEmail As System.Web.UI.WebControls.Button
Protected WithEvents cbDropAndForward As System.Web.UI.WebControls.CheckBox
Protected WithEvents tbDropAndForward As System.Web.UI.WebControls.TextBox
Protected WithEvents lbHelpDropAndForward As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlEmail As System.Web.UI.WebControls.Panel
Protected WithEvents lblRedirectAction As System.Web.UI.WebControls.Label
Protected WithEvents lbHelpRedirect2 As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnCancelRedirect As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbRedirectAddress As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain2 As System.Web.UI.WebControls.Literal
Protected WithEvents tbRedirectTo As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDoNewRedirect As System.Web.UI.WebControls.Button
Protected WithEvents btnDoEditRedirect As System.Web.UI.WebControls.Button
Protected WithEvents pnlRedirect As System.Web.UI.WebControls.Panel
Protected WithEvents lblCountFilters As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxFilters As System.Web.UI.WebControls.Label
Protected WithEvents litFilterList As System.Web.UI.WebControls.Literal
Protected WithEvents litCatchallOutput As System.Web.UI.WebControls.Literal
Protected WithEvents btnAddFilter As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlCatchallOn As System.Web.UI.WebControls.Panel
Protected WithEvents btnHelpCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnEditCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnHelpFilters As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlCatchall As System.Web.UI.WebControls.Panel
Protected WithEvents btnCancelCatchall As System.Web.UI.WebControls.HyperLink
Protected WithEvents btnHelpCatchallFromCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnDoEditCatchall As System.Web.UI.WebControls.Button
Protected WithEvents selCatchall As System.Web.UI.WebControls.DropDownList
Protected WithEvents btnHelpFilterFromFilter As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlFilter As System.Web.UI.WebControls.Panel
Protected WithEvents btnCancelFilter As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbNewFilter As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain3 As System.Web.UI.WebControls.Literal
Protected WithEvents btnDoAddFilter As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Dim DomainName As String = "test4.com"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'change that DomainName now!

If Not IsPostBack Then
Select Case Request.QueryString.Get("action")
Case "edit"
Select Case Request.QueryString.Get("type")
Case "redir"
btnCancelRedirect.NavigateUrl = Request.Path
litDomain2.Text = "@" & DomainName
lblRedirectAction.Text = "Edit"
btnDoNewRedirect.Visible = False
btnDoEditRedirect.Visible = True
pnlDefault.Visible = False
pnlRedirect.Visible = True

Dim d As New SWMail.Domain(DomainName)
Dim mb As SWMail.Domain.Mailbox()
mb = d.GetRedirects(Request.QueryString.Get("name"))
If mb.GetLength(0) = 1 Then
tbRedirectAddress.Text = mb(0).Name
Session.Item("oldname") = mb(0).Name
Session.Item("oldredir") = mb(0).Redirect
tbRedirectTo.Text = mb(0).Redirect
Else
GoDefault()
End If

Case Else
litDomain1.Text = "@" & DomainName
lblEmailAction.Text = "Edit"
btnCancelEmail.NavigateUrl = Request.Path
pnlDefault.Visible = False
pnlEmail.Visible = True
btnDoNewEmail.Visible = False
btnDoSaveEmail.Visible = True
lblLeaveBlank.Visible = True
Dim d As New SWMail.Domain(DomainName)
Dim mb As SWMail.Domain.Mailbox()
mb = d.GetMailboxes(Request.QueryString.Get("name"))
If mb.GetLength(0) = 1 Then
tbEmail.Text = mb(0).Name
Session.Item("oldname") = mb(0).Name
Session.Item("oldredir") = mb(0).Redirect
cbDropAndForward.Checked = mb(0).Redirected
tbDropAndForward.Text = mb(0).Redirect
Else
GoDefault()
End If
End Select

Case "help"
Select Case Request.QueryString.Get("topic")
Case "copyto"
ThrowHelp("You have the option to automatically forward messages sent to you to another email address.<br>IMPORTANT: This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to forward all messages to another email, <i>and don't plan on checking this one</i>, use a <i>redirect</i> address instead.")
Case "filter"
btnHelpFilters_Click(sender, e)
Case "catchall"
btnHelpCatchall_Click(sender, e)
End Select
GoDefault()
Case "delete"
If Request.QueryString.Get("confirm") = "true" Then
DeleteBox(Request.QueryString.Get("name"))
Else
Select Case Request.QueryString.Get("type")
Case "filter"
DeleteBox(Request.QueryString.Get("name"))
Case "redir"
ThrowWarning("Are you sure you want to delet this redirect: ""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""?<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
Case Else
ThrowWarning("If you delete this email address (""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""), all settings and messages that are currently on the server will be deleted.<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
End Select
GoDefault()
End If
Case Else
GoDefault()
End Select
Else
End If
End Sub

Public Sub DeleteBox(ByVal name As String)
Dim d As New SWMail.Domain(DomainName)
'Throw error first, it won't show up if things go ok...
ThrowError("Mailbox deletion failed. Try again or contact support.")
GoDefault(Not d.DeleteMailbox(name))
End Sub
Public Sub InitBoxes()
Dim d As New SWMail.Domain(DomainName)
lblMaxBoxes.Text = d.MaxBoxes
lblCountBoxes.Text = d.CountBoxes
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetMailboxes
If mbs.GetLength(0) > 0 Then
litMailboxList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litMailboxList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Forwarded To:&nbsp;&nbsp;<a style=""font-size:8pt;font-weight:normal;"" href=""" & Request.Path & "?action=help&topic=copyto"">What's This?</a></td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litMailboxList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell(mb.RedirectHTML, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
"</tr>"
Next
litMailboxList.Text &= "</table>"
Else
litMailboxList.Text = "&nbsp;&nbsp;There are no addresses defined at this time."
End If
End Sub
Public Sub InitRedirects()
Dim d As New SWMail.Domain(DomainName)
lblMaxRedirects.Text = d.MaxRedirects
lblCountRedirects.Text = d.CountRedirects
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetRedirects
If mbs.GetLength(0) > 0 Then
litRedirectList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litRedirectList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Redirected To:</td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litRedirectList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell(mb.RedirectHTML, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&type=redir&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&type=redir&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
"</tr>"
Next
litRedirectList.Text &= "</table>"
Else
litRedirectList.Text = "&nbsp;&nbsp;There are no redirect addresses defined at this time."
End If
End Sub
Public Sub InitCatchall()
Dim d As New SWMail.Domain(DomainName)
If d.CatchallEnabled Then
litCatchallOutput.Text = "&nbsp;&nbsp;Catchall <b><i>IS</i></b> Enabled.<br>" & _
"&nbsp;&nbsp;&nbsp;Catchall address: <b><i>" & d.Catchall & "@" & DomainName & "</i></b>"
Else
litCatchallOutput.Text = "&nbsp;&nbsp;Catchall is <b><i>NOT</i></b> Enabled."
End If

lblMaxFilters.Text = d.MaxFilters
lblCountFilters.Text = d.CountFilters
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetFilters
If mbs.GetLength(0) > 0 Then
litFilterList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litFilterList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address to filter:</td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litFilterList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&type=filter&name=" & mb.Name & """>Delete</a>", BGGrey, "", "L") & _
"</tr>"
Next
litFilterList.Text &= "</table>"
Else
litFilterList.Text = "&nbsp;&nbsp;There are no catchall filters defined at this time."
End If
End Sub
Private Function LineItemCell(ByVal text As String, ByVal grey As Boolean, Optional ByVal width As String = "", Optional ByVal little As String = "") As String
Dim r As String = "<td "
If width <> "" Then r &= "width=""" & width & """ "

r &= "class=lineItem" & little & " style=""background-color:#"

If grey Then
r &= "eeeef5"
Else
r &= "ffffff"
End If

r &= ";"">" & text & "</td>"

Return r
End Function

Private Sub btnNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewEmail.Click
Dim d As New SWMail.Domain(DomainName)
If d.MaxBoxes > d.CountBoxes Then
btnCancelEmail.NavigateUrl = Request.Path
lblLeaveBlank.Visible = False
litDomain1.Text = "@" & DomainName
lblEmailAction.Text = "New"
btnDoNewEmail.Visible = True
btnDoSaveEmail.Visible = False
pnlDefault.Visible = False
pnlEmail.Visible = True
Else
ThrowError("You have reached your mailbox limit.<br>Before adding new mailboxes you need to delete current ones or contact support for more information on increasing your limit.")
End If

End Sub

Private Sub btnDoNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoNewEmail.Click
Dim sAddress As String = tbEmail.Text.ToLower.Trim
Dim sPassword As String = tbPassword.Text.ToLower.Trim
Dim sCPassword As String = tbConfirmPassword.Text.ToLower.Trim
Dim sRedirect As String = tbDropAndForward.Text.ToLower.Trim

Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
validAddress.Validate(sAddress)
If validAddress.IsValid Then
Dim validPass As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Password)
validPass.Validate(sPassword, sCPassword)
If validPass.IsValid Then
Dim bRedirect As Boolean = True
If cbDropAndForward.Checked Then
Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
validRedirect.Validate(sRedirect)
bRedirect = validRedirect.IsValid
Else
sRedirect = ""
End If
If bRedirect Then
tbEmail.Text = ""
Dim d As New SWMail.Domain(DomainName)
If d.NewMailbox(sAddress, sPassword, sRedirect) Then
ThrowSuccess("New Mailbox created.")
GoDefault(False, True)
Else
ThrowError("Mailbox creation failed.<br>Please make sure the mailbox name is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
End If
Else
ThrowError("Mailbox creation failed.<br>Check forwarding email address.")
End If

Else
ThrowError(validPass.ErrorMessage)
End If
Else
ThrowError(validAddress.ErrorMessage)
End If
End Sub

Private Sub GoDefault(Optional ByVal ErrorPanel As Boolean = False, Optional ByVal SuccessPanel As Boolean = False)
pnlError.Visible = ErrorPanel
pnlSuccess.Visible = SuccessPanel
pnlDefault.Visible = True
pnlEmail.Visible = False
pnlRedirect.Visible = False
pnlCatchall.Visible = False
pnlFilter.Visible = False
InitBoxes()
InitRedirects()
InitCatchall()
End Sub
Private Sub ThrowError(ByVal msg As String)
pnlError.Visible = True
litErrorMessage.Text = msg
End Sub
Private Sub ThrowSuccess(ByVal msg As String)
pnlSuccess.Visible = True
litSuccessMessage.Text = msg
End Sub
Private Sub ThrowHelp(ByVal msg As String)
litHelpMessage.Text = msg
pnlHelp.Visible = True
End Sub
Private Sub ThrowWarning(ByVal msg As String, ByVal continue As String)
hlContinue.NavigateUrl = continue
litWarningMessage.Text = msg
pnlWarning.Visible = True
End Sub

Private Sub lbHelpDropAndForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbHelpDropAndForward.Click
ThrowHelp("Check this box to automatically forward messages to any other email address.<br>IMPORTANT: This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to

Tim

Part 2

Postby Tim » Thu Jul 08, 2004 3:12 am

The forum cut off the post, here's the bottom half:





In the Web App Project, reference your Class library (SWMail).

Now, in the web app project we are going to create a new user control.
Call it "EmailApp.ascx"
Heres the code behind:(EmailApp.ascx.vb)

Code: Select all


Public Class EmailApp
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents litErrorMessage As System.Web.UI.WebControls.Literal
    Protected WithEvents pnlError As System.Web.UI.WebControls.Panel
    Protected WithEvents litWarningMessage As System.Web.UI.WebControls.Literal
    Protected WithEvents hlContinue As System.Web.UI.WebControls.HyperLink
    Protected WithEvents pnlWarning As System.Web.UI.WebControls.Panel
    Protected WithEvents litSuccessMessage As System.Web.UI.WebControls.Literal
    Protected WithEvents pnlSuccess As System.Web.UI.WebControls.Panel
    Protected WithEvents litHelpMessage As System.Web.UI.WebControls.Literal
    Protected WithEvents pnlHelp As System.Web.UI.WebControls.Panel
    Protected WithEvents lblCountBoxes As System.Web.UI.WebControls.Label
    Protected WithEvents lblMaxBoxes As System.Web.UI.WebControls.Label
    Protected WithEvents btnNewEmail As System.Web.UI.WebControls.LinkButton
    Protected WithEvents litMailboxList As System.Web.UI.WebControls.Literal
    Protected WithEvents lbHelpRedirect As System.Web.UI.WebControls.LinkButton
    Protected WithEvents lblCountRedirects As System.Web.UI.WebControls.Label
    Protected WithEvents lblMaxRedirects As System.Web.UI.WebControls.Label
    Protected WithEvents lbNewRedirect As System.Web.UI.WebControls.LinkButton
    Protected WithEvents litRedirectList As System.Web.UI.WebControls.Literal
    Protected WithEvents pnlDefault As System.Web.UI.WebControls.Panel
    Protected WithEvents lblEmailAction As System.Web.UI.WebControls.Label
    Protected WithEvents btnCancelEmail As System.Web.UI.WebControls.HyperLink
    Protected WithEvents tbEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents litDomain1 As System.Web.UI.WebControls.Literal
    Protected WithEvents tbPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblLeaveBlank As System.Web.UI.WebControls.Label
    Protected WithEvents tbConfirmPassword As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnDoNewEmail As System.Web.UI.WebControls.Button
    Protected WithEvents btnDoSaveEmail As System.Web.UI.WebControls.Button
    Protected WithEvents cbDropAndForward As System.Web.UI.WebControls.CheckBox
    Protected WithEvents tbDropAndForward As System.Web.UI.WebControls.TextBox
    Protected WithEvents lbHelpDropAndForward As System.Web.UI.WebControls.LinkButton
    Protected WithEvents pnlEmail As System.Web.UI.WebControls.Panel
    Protected WithEvents lblRedirectAction As System.Web.UI.WebControls.Label
    Protected WithEvents lbHelpRedirect2 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents btnCancelRedirect As System.Web.UI.WebControls.HyperLink
    Protected WithEvents tbRedirectAddress As System.Web.UI.WebControls.TextBox
    Protected WithEvents litDomain2 As System.Web.UI.WebControls.Literal
    Protected WithEvents tbRedirectTo As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnDoNewRedirect As System.Web.UI.WebControls.Button
    Protected WithEvents btnDoEditRedirect As System.Web.UI.WebControls.Button
    Protected WithEvents pnlRedirect As System.Web.UI.WebControls.Panel
    Protected WithEvents lblCountFilters As System.Web.UI.WebControls.Label
    Protected WithEvents lblMaxFilters As System.Web.UI.WebControls.Label
    Protected WithEvents litFilterList As System.Web.UI.WebControls.Literal
    Protected WithEvents litCatchallOutput As System.Web.UI.WebControls.Literal
    Protected WithEvents btnAddFilter As System.Web.UI.WebControls.LinkButton
    Protected WithEvents pnlCatchallOn As System.Web.UI.WebControls.Panel
    Protected WithEvents btnHelpCatchall As System.Web.UI.WebControls.LinkButton
    Protected WithEvents btnEditCatchall As System.Web.UI.WebControls.LinkButton
    Protected WithEvents btnHelpFilters As System.Web.UI.WebControls.LinkButton
    Protected WithEvents pnlCatchall As System.Web.UI.WebControls.Panel
    Protected WithEvents btnCancelCatchall As System.Web.UI.WebControls.HyperLink
    Protected WithEvents btnHelpCatchallFromCatchall As System.Web.UI.WebControls.LinkButton
    Protected WithEvents btnDoEditCatchall As System.Web.UI.WebControls.Button
    Protected WithEvents selCatchall As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnHelpFilterFromFilter As System.Web.UI.WebControls.LinkButton
    Protected WithEvents pnlFilter As System.Web.UI.WebControls.Panel
    Protected WithEvents btnCancelFilter As System.Web.UI.WebControls.HyperLink
    Protected WithEvents tbNewFilter As System.Web.UI.WebControls.TextBox
    Protected WithEvents litDomain3 As System.Web.UI.WebControls.Literal
    Protected WithEvents btnDoAddFilter As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region
    Dim DomainName As String = "test4.com"
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   'change that DomainName now!

        If Not IsPostBack Then
            Select Case Request.QueryString.Get("action")
                Case "edit"
                    Select Case Request.QueryString.Get("type")
                        Case "redir"
                            btnCancelRedirect.NavigateUrl = Request.Path
                            litDomain2.Text = "@" & DomainName
                            lblRedirectAction.Text = "Edit"
                            btnDoNewRedirect.Visible = False
                            btnDoEditRedirect.Visible = True
                            pnlDefault.Visible = False
                            pnlRedirect.Visible = True

                            Dim d As New SWMail.Domain(DomainName)
                            Dim mb As SWMail.Domain.Mailbox()
                            mb = d.GetRedirects(Request.QueryString.Get("name"))
                            If mb.GetLength(0) = 1 Then
                                tbRedirectAddress.Text = mb(0).Name
                                Session.Item("oldname") = mb(0).Name
                                Session.Item("oldredir") = mb(0).Redirect
                                tbRedirectTo.Text = mb(0).Redirect
                            Else
                                GoDefault()
                            End If

                        Case Else
                            litDomain1.Text = "@" & DomainName
                            lblEmailAction.Text = "Edit"
                            btnCancelEmail.NavigateUrl = Request.Path
                            pnlDefault.Visible = False
                            pnlEmail.Visible = True
                            btnDoNewEmail.Visible = False
                            btnDoSaveEmail.Visible = True
                            lblLeaveBlank.Visible = True
                            Dim d As New SWMail.Domain(DomainName)
                            Dim mb As SWMail.Domain.Mailbox()
                            mb = d.GetMailboxes(Request.QueryString.Get("name"))
                            If mb.GetLength(0) = 1 Then
                                tbEmail.Text = mb(0).Name
                                Session.Item("oldname") = mb(0).Name
                                Session.Item("oldredir") = mb(0).Redirect
                                cbDropAndForward.Checked = mb(0).Redirected
                                tbDropAndForward.Text = mb(0).Redirect
                            Else
                                GoDefault()
                            End If
                    End Select

                Case "help"
                    Select Case Request.QueryString.Get("topic")
                        Case "copyto"
                            ThrowHelp("You have the option to automatically forward messages sent to you to another email address.<br>IMPORTANT:  This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to forward all messages to another email, <i>and don't plan on checking this one</i>, use a <i>redirect</i> address instead.")
                        Case "filter"
                            btnHelpFilters_Click(sender, e)
                        Case "catchall"
                            btnHelpCatchall_Click(sender, e)
                    End Select
                    GoDefault()
                Case "delete"
                    If Request.QueryString.Get("confirm") = "true" Then
                        DeleteBox(Request.QueryString.Get("name"))
                    Else
                        Select Case Request.QueryString.Get("type")
                            Case "filter"
                                DeleteBox(Request.QueryString.Get("name"))
                            Case "redir"
                                ThrowWarning("Are you sure you want to delet this redirect: ""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""?<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
                            Case Else
                                ThrowWarning("If you delete this email address (""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""), all settings and messages that are currently on the server will be deleted.<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
                        End Select
                        GoDefault()
                    End If
                Case Else
                    GoDefault()
            End Select
        Else
        End If
    End Sub

    Public Sub DeleteBox(ByVal name As String)
        Dim d As New SWMail.Domain(DomainName)
        'Throw error first, it won't show up if things go ok...
        ThrowError("Mailbox deletion failed.  Try again or contact support.")
        GoDefault(Not d.DeleteMailbox(name))
    End Sub
    Public Sub InitBoxes()
        Dim d As New SWMail.Domain(DomainName)
        lblMaxBoxes.Text = d.MaxBoxes
        lblCountBoxes.Text = d.CountBoxes
        Dim mbs As SWMail.Domain.Mailbox()
        mbs = d.GetMailboxes
        If mbs.GetLength(0) > 0 Then
            litMailboxList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
            litMailboxList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Forwarded To:&nbsp;&nbsp;<a style=""font-size:8pt;font-weight:normal;"" href=""" & Request.Path & "?action=help&topic=copyto"">What's This?</a></td><td class=lineHeader>Actions:</td></tr>"
            Dim BGGrey As Boolean = False
            Dim c As Integer = 0
            For Each mb As SWMail.Domain.Mailbox In mbs
                BGGrey = Not BGGrey
                c += 1
                litMailboxList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
                    LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
                    LineItemCell(mb.RedirectHTML, BGGrey) & _
                    LineItemCell("<a href=""" & Request.Path & "?action=delete&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
                    "</tr>"
            Next
            litMailboxList.Text &= "</table>"
        Else
            litMailboxList.Text = "&nbsp;&nbsp;There are no addresses defined at this time."
        End If
    End Sub
    Public Sub InitRedirects()
        Dim d As New SWMail.Domain(DomainName)
        lblMaxRedirects.Text = d.MaxRedirects
        lblCountRedirects.Text = d.CountRedirects
        Dim mbs As SWMail.Domain.Mailbox()
        mbs = d.GetRedirects
        If mbs.GetLength(0) > 0 Then
            litRedirectList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
            litRedirectList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Redirected To:</td><td class=lineHeader>Actions:</td></tr>"
            Dim BGGrey As Boolean = False
            Dim c As Integer = 0
            For Each mb As SWMail.Domain.Mailbox In mbs
                BGGrey = Not BGGrey
                c += 1
                litRedirectList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
                    LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
                    LineItemCell(mb.RedirectHTML, BGGrey) & _
                    LineItemCell("<a href=""" & Request.Path & "?action=delete&type=redir&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&type=redir&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
                    "</tr>"
            Next
            litRedirectList.Text &= "</table>"
        Else
            litRedirectList.Text = "&nbsp;&nbsp;There are no redirect addresses defined at this time."
        End If
    End Sub
    Public Sub InitCatchall()
        Dim d As New SWMail.Domain(DomainName)
        If d.CatchallEnabled Then
            litCatchallOutput.Text = "&nbsp;&nbsp;Catchall <b><i>IS</i></b> Enabled.<br>" & _
            "&nbsp;&nbsp;&nbsp;Catchall address: <b><i>" & d.Catchall & "@" & DomainName & "</i></b>"
        Else
            litCatchallOutput.Text = "&nbsp;&nbsp;Catchall is <b><i>NOT</i></b> Enabled."
        End If

        lblMaxFilters.Text = d.MaxFilters
        lblCountFilters.Text = d.CountFilters
        Dim mbs As SWMail.Domain.Mailbox()
        mbs = d.GetFilters
        If mbs.GetLength(0) > 0 Then
            litFilterList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
            litFilterList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address to filter:</td><td class=lineHeader>Actions:</td></tr>"
            Dim BGGrey As Boolean = False
            Dim c As Integer = 0
            For Each mb As SWMail.Domain.Mailbox In mbs
                BGGrey = Not BGGrey
                c += 1
                litFilterList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
                    LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
                    LineItemCell("<a href=""" & Request.Path & "?action=delete&type=filter&name=" & mb.Name & """>Delete</a>", BGGrey, "", "L") & _
                    "</tr>"
            Next
            litFilterList.Text &= "</table>"
        Else
            litFilterList.Text = "&nbsp;&nbsp;There are no catchall filters defined at this time."
        End If
    End Sub
    Private Function LineItemCell(ByVal text As String, ByVal grey As Boolean, Optional ByVal width As String = "", Optional ByVal little As String = "") As String
        Dim r As String = "<td "
        If width <> "" Then r &= "width=""" & width & """ "

        r &= "class=lineItem" & little & " style=""background-color:#"

        If grey Then
            r &= "eeeef5"
        Else
            r &= "ffffff"
        End If

        r &= ";"">" & text & "</td>"

        Return r
    End Function

    Private Sub btnNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewEmail.Click
        Dim d As New SWMail.Domain(DomainName)
        If d.MaxBoxes > d.CountBoxes Then
            btnCancelEmail.NavigateUrl = Request.Path
            lblLeaveBlank.Visible = False
            litDomain1.Text = "@" & DomainName
            lblEmailAction.Text = "New"
            btnDoNewEmail.Visible = True
            btnDoSaveEmail.Visible = False
            pnlDefault.Visible = False
            pnlEmail.Visible = True
        Else
            ThrowError("You have reached your mailbox limit.<br>Before adding new mailboxes you need to delete current ones or contact support for more information on increasing your limit.")
        End If

    End Sub

    Private Sub btnDoNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoNewEmail.Click
        Dim sAddress As String = tbEmail.Text.ToLower.Trim
        Dim sPassword As String = tbPassword.Text.ToLower.Trim
        Dim sCPassword As String = tbConfirmPassword.Text.ToLower.Trim
        Dim sRedirect As String = tbDropAndForward.Text.ToLower.Trim

        Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
        validAddress.Validate(sAddress)
        If validAddress.IsValid Then
            Dim validPass As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Password)
            validPass.Validate(sPassword, sCPassword)
            If validPass.IsValid Then
                Dim bRedirect As Boolean = True
                If cbDropAndForward.Checked Then
                    Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
                    validRedirect.Validate(sRedirect)
                    bRedirect = validRedirect.IsValid
                Else
                    sRedirect = ""
                End If
                If bRedirect Then
                    tbEmail.Text = ""
                    Dim d As New SWMail.Domain(DomainName)
                    If d.NewMailbox(sAddress, sPassword, sRedirect) Then
                        ThrowSuccess("New Mailbox created.")
                        GoDefault(False, True)
                    Else
                        ThrowError("Mailbox creation failed.<br>Please make sure the mailbox name is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
                    End If
                Else
                    ThrowError("Mailbox creation failed.<br>Check forwarding email address.")
                End If

            Else
                ThrowError(validPass.ErrorMessage)
            End If
        Else
            ThrowError(validAddress.ErrorMessage)
        End If
    End Sub

    Private Sub GoDefault(Optional ByVal ErrorPanel As Boolean = False, Optional ByVal SuccessPanel As Boolean = False)
        pnlError.Visible = ErrorPanel
        pnlSuccess.Visible = SuccessPanel
        pnlDefault.Visible = True
        pnlEmail.Visible = False
        pnlRedirect.Visible = False
        pnlCatchall.Visible = False
        pnlFilter.Visible = False
        InitBoxes()
        InitRedirects()
        InitCatchall()
    End Sub
    Private Sub ThrowError(ByVal msg As String)
        pnlError.Visible = True
        litErrorMessage.Text = msg
    End Sub
    Private Sub ThrowSuccess(ByVal msg As String)
        pnlSuccess.Visible = True
        litSuccessMessage.Text = msg
    End Sub
    Private Sub ThrowHelp(ByVal msg As String)
        litHelpMessage.Text = msg
        pnlHelp.Visible = True
    End Sub
    Private Sub ThrowWarning(ByVal msg As String, ByVal continue As String)
        hlContinue.NavigateUrl = continue
        litWarningMessage.Text = msg
        pnlWarning.Visible = True
    End Sub

    Private Sub lbHelpDropAndForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbHelpDropAndForward.Click
        ThrowHelp("Check this box to automatically forward messages to any other email address.<br>IMPORTANT:  This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to forward all messages to another email, <i>and don't plan on checking this one</i>, use a <i>redirect</i> address instead.")
    End Sub

    Private Sub btnDoSaveEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoSaveEmail.Click
        Dim sAddress As String = tbEmail.Text.ToLower.Trim
        Dim sPassword As String = tbPassword.Text.ToLower.Trim
        Dim sCPassword As String = tbConfirmPassword.Text.ToLower.Trim
        Dim sRedirect As String = tbDropAndForward.Text.ToLower.Trim
        Dim sErr As String

        Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
        validAddress.Validate(sAddress)
        If validAddress.IsValid Then
            Dim vPass As Boolean = True
            If sPassword <> "" Then
                Dim validPass As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Password)
                validPass.Validate(sPassword, sCPassword)
                vPass = validPass.IsValid
                sErr = validPass.ErrorMessage
            End If
            If vPass Then
                Dim bRedirect As Boolean = True
                If cbDropAndForward.Checked Then
                    Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
                    validRedirect.Validate(sRedirect)
                    bRedirect = validRedirect.IsValid
                Else
                    sRedirect = ""
                End If
                If bRedirect Then
                    Dim d As New SWMail.Domain(DomainName)
                    If d.EditMailbox(Session.Item("oldname"), sAddress, sPassword, sRedirect) Then
                        tbEmail.Text = ""
                        tbDropAndForward.Text = ""
                        ThrowSuccess("Mailbox changes saved.")
                        GoDefault(False, True)
                    Else
                        tbEmail.Text = Session.Item("oldname")
                        tbDropAndForward.Text = Session.Item("oldredir")
                        ThrowError("Mailbox edit failed.<br>Please make sure the mailbox name is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
                    End If
                Else
                    ThrowError("Mailbox edit failed.<br>Check forwarding email address.")
                End If

            Else
                ThrowError(sErr)
            End If
        Else
            ThrowError(validAddress.ErrorMessage)
        End If

    End Sub

    Private Sub lbHelpRedirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbHelpRedirect.Click, lbHelpRedirect2.Click
        ThrowHelp("A redirect address is an email address set up with an address ""@" & DomainName & """ that gets all its mail forwarded to an email address that you already use, like ""yourcompany@yahoo.com"".<br>The email address doesn't really exist (you can't check its mail), it just exists as a ""shortcut"" to another address.")
    End Sub

    Private Sub lbNewRedirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbNewRedirect.Click
        Dim d As New SWMail.Domain(DomainName)
        If d.MaxRedirects > d.CountRedirects Then
            btnCancelRedirect.NavigateUrl = Request.Path
            litDomain2.Text = "@" & DomainName
            lblRedirectAction.Text = "New"
            btnDoNewRedirect.Visible = True
            btnDoEditRedirect.Visible = False
            pnlDefault.Visible = False
            pnlRedirect.Visible = True
        Else
            ThrowError("You have reached your redirect limit.<br>Before adding new redirects you need to delete current ones or contact support for more information on increasing your limit.")
        End If
    End Sub

    Private Sub btnDoNewRedirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoNewRedirect.Click
        Dim sAddress As String = tbRedirectAddress.Text.ToLower.Trim
        Dim sRedirectTo As String = tbRedirectTo.Text.ToLower.Trim

        Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
        validAddress.Validate(sAddress)
        If validAddress.IsValid Then
            If sRedirectTo <> "" Then
                Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
                validRedirect.Validate(sRedirectTo)
                If validRedirect.IsValid Then
                    tbRedirectAddress.Text = ""
                    tbRedirectTo.Text = ""
                    Dim d As New SWMail.Domain(DomainName)
                    If d.NewRedirect(sAddress, sRedirectTo) Then
                        ThrowSuccess("New redirect address created.")
                        GoDefault(False, True)
                    Else
                        ThrowError("Redirect address creation failed.<br>Please make sure the redirected address is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
                    End If
                Else
                    ThrowError(validRedirect.ErrorMessage)
                End If
            Else
                ThrowError("The address for messages to be redirected to is required.")
            End If
        Else
            ThrowError(validAddress.ErrorMessage)
        End If

    End Sub

    Private Sub btnDoEditRedirect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoEditRedirect.Click
        Dim sAddress As String = tbRedirectAddress.Text.ToLower.Trim
        Dim sRedirect As String = tbRedirectTo.Text.ToLower.Trim

        Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
        validAddress.Validate(sAddress)
        If validAddress.IsValid Then
            If sRedirect <> "" Then

                Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
                validRedirect.Validate(sRedirect)
                If validRedirect.IsValid Then
                    Dim d As New SWMail.Domain(DomainName)
                    If d.EditRedirect(Session.Item("oldname"), sAddress, sRedirect) Then
                        tbRedirectAddress.Text = ""
                        tbRedirectTo.Text = ""
                        ThrowSuccess("Redirect address changes saved.")
                        GoDefault(False, True)
                    Else
                        ThrowError("Redirect address edit failed.<br>Please make sure the redirect address is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
                        tbRedirectAddress.Text = Session.Item("oldname")
                        tbRedirectTo.Text = Session.Item("oldredir")
                    End If
                Else
                    ThrowError(validRedirect.ErrorMessage)
                End If
            Else
                ThrowError("The address for messages to be redirected to is required.")
            End If
        Else
            ThrowError(validAddress.ErrorMessage)
        End If
    End Sub

    Private Sub btnHelpCatchall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelpCatchall.Click, btnHelpCatchallFromCatchall.Click
        ThrowHelp("A ""Catchall"" address is an address (""@" & DomainName & """), that already exists, that all mail sent to any address @" & DomainName & " <i>not going to another mailbox</i>, gets sent to." & _
        "<br>It is an excellent way to handle mail, for instance you can have one mailbox (""yourname@" & DomainName & """) but publicize the email addresses:<br>""info@" & DomainName & """, ""sales@" & DomainName & """, and ""support@" & DomainName & """, or any other address you choose." & _
        "<br>All email sent to those addresses, unless those addresses exist as regular mailboxes or redirect addresses, (or you have set up a ""<a href=""" & Request.Path & "?action=help&topic=filter"">Catchall Filter</a>"" for) will be sent to your mailbox." & _
        "<br>It is an excellent tool, but you <i>will</i> get more spam (you don't get some spam, because it is sent to mailboxes that don't exist; using a catchall, any address @" & DomainName & " technically exists.")
    End Sub

    Private Sub btnHelpFilters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelpFilters.Click, btnHelpFilterFromFilter.Click
        ThrowHelp("To understand this help message, please read the help message on ""<a href=""" & Request.Path & "?action=help&topic=catchall"">Catchall</a>"" addresses first." & _
        "<br><br>Catchall filters are address set up that refuse mail, so that you can cut down on the amount of spam you receive." & _
        "<br>As an example, one of our clients once signed up for some free jellybeans.  He entered his email address as ""jellybeanman@hisdomain.com""." & _
        "<br>Well, we don't know if he ever got his free jellybeans, but 6 months later he was getting <i>hundreds</i> of emails a week (received by his catchall) that were addressed to ""jellybeanman@hisdomain.com""." & _
        "<br>The moral of the story is not to sign up for ""free"" stuff online.<br>But if you do, use a catchall filter address (you can use any address, but once it has served its purpose, block it).")
    End Sub

    Private Sub btnEditCatchall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditCatchall.Click
        Dim d As New SWMail.Domain(DomainName)
        selCatchall.Items.Clear()
        selCatchall.Items.Add(New Web.UI.WebControls.ListItem("No Catchall", ""))

        For Each mb As SWMail.Domain.Mailbox In d.GetEnabled
            selCatchall.Items.Add(New Web.UI.WebControls.ListItem(mb.Name & "@" & DomainName, mb.Name))
        Next
        selCatchall.SelectedValue = d.Catchall
        btnCancelCatchall.NavigateUrl = Request.Path
        pnlDefault.Visible = False
        pnlCatchall.Visible = True
    End Sub

    Private Sub btnDoEditCatchall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoEditCatchall.Click
        Dim d As New SWMail.Domain(DomainName)
        d.Catchall = selCatchall.SelectedValue
        GoDefault()
    End Sub

    Private Sub btnAddFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddFilter.Click
        Dim d As New SWMail.Domain(DomainName)
        If d.MaxFilters > d.CountFilters Then
            btnCancelFilter.NavigateUrl = Request.Path
            litDomain3.Text = DomainName
            pnlDefault.Visible = False
            pnlFilter.Visible = True
        Else
            ThrowError("You have reached your filter limit.<br>Before adding new filters you need to delete current ones or contact support for more information on increasing your limit.")
        End If
    End Sub

    Private Sub btnDoAddFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoAddFilter.Click
        Dim sAddress As String = tbNewFilter.Text.ToLower.Trim

        Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
        validAddress.Validate(sAddress)
        If validAddress.IsValid Then
            tbNewFilter.Text = ""
                    Dim d As New SWMail.Domain(DomainName)
            If d.NewFilter(sAddress) Then
                ThrowSuccess("New Catchall Filter created.")
                GoDefault(False, True)
            Else
                ThrowError("Filter creation failed.<br>Please make sure the filter name is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
            End If
        Else
            ThrowError(validAddress.ErrorMessage)
        End If
    End Sub
End Class



Finally, here's the HTML for EmailApp.ascx

Code: Select all


<%@ Control Language="vb" AutoEventWireup="false" Codebehind="EmailApp.ascx.vb" Inherits="SWMailDev.EmailApp" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<style type="text/css">.bodyBox A:link {
   COLOR: #0000cc
}
.bodyBox A:active {
   COLOR: #0000cc
}
.bodyBox A:visited {
   COLOR: #0000cc
}
.bodyBox A:hover {
   COLOR: #6666cc
}
.bodyBox {
   BORDER-RIGHT: #000099 1px solid; PADDING-RIGHT: 6px; BORDER-TOP: #000099 1px solid; PADDING-LEFT: 6px; FONT-SIZE: 12px; PADDING-BOTTOM: 12px; BORDER-LEFT: #000099 1px solid; WIDTH: 100%; PADDING-TOP: 8px; BORDER-BOTTOM: #000099 1px solid; BACKGROUND-COLOR: #ddddee
}
.boxHeader {
   MARGIN-BOTTOM: 12px; WIDTH: 100%; BORDER-BOTTOM: #333399 1px groove
}
.lineItem {
   PADDING-LEFT: 12px; FONT-SIZE: 12px; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px groove
}
.lineItemL {
   PADDING-LEFT: 12px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px groove
}
.lineHeader {
   PADDING-LEFT: 12px; FONT-WEIGHT: bold; FONT-SIZE: 12px; PADDING-BOTTOM: 4px; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px groove; BACKGROUND-COLOR: #bbbbcc
}
</style>
<div id="EmailAppHolder" style="COLOR: #000000; FONT-FAMILY: Tahoma, Arial, Helvetica, Sans-Serif; BACKGROUND-COLOR: #ffffff"><asp:panel id="pnlError" runat="server" Visible="false" EnableViewState="False">
      <DIV style="FONT-SIZE: 14px; WIDTH: 100%; COLOR: #cc0000; TEXT-ALIGN: center" ms_positioning="FlowLayout">
         <asp:Literal id="litErrorMessage" runat="server"></asp:Literal><BR>
         <BR>
      </DIV>
   </asp:panel><asp:panel id="pnlWarning" runat="server" Visible="false" EnableViewState="False">
      <DIV style="FONT-SIZE: 12px; WIDTH: 100%; COLOR: #cc0000" ms_positioning="FlowLayout"><STRONG>WARNING:<BR>
         </STRONG>
         <asp:Literal id="litWarningMessage" runat="server"></asp:Literal><BR>
         <BR>
         <asp:HyperLink id="hlContinue" runat="server" ForeColor="#CC0000" Font-Bold="True">Click Here to Continue...</asp:HyperLink><BR>
         <BR>
      </DIV>
   </asp:panel><asp:panel id="pnlSuccess" runat="server" Visible="false" EnableViewState="False">
      <DIV style="FONT-SIZE: 14px; WIDTH: 100%; COLOR: #00cc00; TEXT-ALIGN: center" ms_positioning="FlowLayout">
         <asp:Literal id="litSuccessMessage" runat="server"></asp:Literal><BR>
         <BR>
      </DIV>
   </asp:panel><asp:panel id="pnlHelp" runat="server" Visible="false" EnableViewState="False">
      <DIV style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 12px; WIDTH: 100%" ms_positioning="FlowLayout"><STRONG>Integrated
            Help System:<BR>
         </STRONG>
         <asp:Literal id="litHelpMessage" runat="server"></asp:Literal><BR>
         <BR>
      </DIV>
   </asp:panel><asp:panel id="pnlDefault" runat="server">
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Email Addresses:&nbsp;&nbsp; (
                     <asp:Label id="lblCountBoxes" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Total
                     out of
                     <asp:Label id="lblMaxBoxes" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Max
                     )</TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:LinkButton id="btnNewEmail" runat="server">Create New Address</asp:LinkButton></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <asp:Literal id="litMailboxList" runat="server"></asp:Literal></DIV>
      </DIV>
      <BR>
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table10" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Redirect Addresses:&nbsp;&nbsp;
                     <asp:LinkButton id="lbHelpRedirect" runat="server" Font-Size="8pt">What's This?</asp:LinkButton>&nbsp;
                     (
                     <asp:Label id="lblCountRedirects" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Total
                     out of
                     <asp:Label id="lblMaxRedirects" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Max
                     )</TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:LinkButton id="lbNewRedirect" runat="server">Create New Redirect</asp:LinkButton></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <asp:Literal id="litRedirectList" runat="server"></asp:Literal></DIV>
      </DIV>
      <BR>
      <BR>
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table1000" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Catchall:&nbsp;&nbsp;
                     <asp:LinkButton id="btnHelpCatchall" runat="server" Font-Size="8pt">What's This?</asp:LinkButton>&nbsp;
                  </TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:LinkButton id="btnEditCatchall" runat="server">Edit Catchall Address</asp:LinkButton></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <asp:Literal id="litCatchallOutput" runat="server"></asp:Literal></DIV>
      </DIV>
      <BR>
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table100" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Catchall Filters:&nbsp;&nbsp;
                     <asp:LinkButton id="btnHelpFilters" runat="server" Font-Size="8pt">What's This?</asp:LinkButton>&nbsp;
                     (
                     <asp:Label id="lblCountFilters" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Total
                     out of
                     <asp:Label id="lblMaxFilters" runat="server" Font-Bold="True">0</asp:Label>&nbsp;Max
                     )&nbsp;&nbsp;</TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:LinkButton id="btnAddFilter" runat="server">Create New Catchall Filter</asp:LinkButton></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <asp:Literal id="litFilterList" runat="server"></asp:Literal></DIV>
      </DIV>
   </asp:panel><asp:panel id="pnlEmail" runat="server" Visible="False">
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">
                     <asp:Label id="lblEmailAction" runat="server">Label</asp:Label>&nbsp;Email
                     Address:</TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:Hyperlink id="btnCancelEmail" runat="server">Cancel</asp:Hyperlink></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <TABLE id="Table3" cellSpacing="10" cellPadding="0" width="600" align="center" border="0">
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" vAlign="top" align="right" width="30%">&nbsp;&nbsp;&nbsp;
                     Address: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px" width="70%">
                     <asp:TextBox id="tbEmail" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="150px"></asp:TextBox>&nbsp;
                     <asp:Literal id="litDomain1" runat="server"></asp:Literal></TD>
               </TR>
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px; HEIGHT: 22px" vAlign="top" align="right"
                     width="30%">&nbsp; Password: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px; HEIGHT: 22px" width="70%">
                     <asp:TextBox id="tbPassword" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="150px" TextMode="Password"></asp:TextBox>&nbsp;&nbsp;
                     <asp:Label id="lblLeaveBlank" runat="server">Leave Blank to keep old password.</asp:Label></TD>
               </TR>
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" vAlign="top" align="right" width="30%">&nbsp;
                     Confirm Password: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px" width="70%">
                     <asp:TextBox id="tbConfirmPassword" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="150px" TextMode="Password"></asp:TextBox>&nbsp;&nbsp;&nbsp;
                  </TD>
               </TR>
               <TR>
                  <TD align="center" colSpan="2">
                     <asp:Button id="btnDoNewEmail" runat="server" Text="Add New Email"></asp:Button>
                     <asp:Button id="btnDoSaveEmail" runat="server" Text="Save Changes"></asp:Button></TD>
               </TR>
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" align="right">
                     <asp:CheckBox id="cbDropAndForward" runat="server" Text="Copy messages to:"></asp:CheckBox>&nbsp;</TD>
                  <TD style="FONT-SIZE: 8pt" align="left">
                     <asp:TextBox id="tbDropAndForward" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="250px"></asp:TextBox>&nbsp;
                     <asp:LinkButton id="lbHelpDropAndForward" runat="server">What's This?</asp:LinkButton></TD>
               </TR>
            </TABLE>
         </DIV>
      </DIV>
   </asp:panel><asp:panel id="pnlRedirect" runat="server" Visible="False">
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table20" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">
                     <asp:Label id="lblRedirectAction" runat="server">Label</asp:Label>&nbsp;Redirect
                     Address:&nbsp;
                     <asp:LinkButton id="lbHelpRedirect2" runat="server" Font-Size="8pt">What's This?</asp:LinkButton></TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:Hyperlink id="btnCancelRedirect" runat="server">Cancel</asp:Hyperlink></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <TABLE id="Table30" cellSpacing="10" cellPadding="0" width="600" align="center" border="0">
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" vAlign="top" align="right" width="30%">&nbsp;&nbsp;&nbsp;
                     Address: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px" width="70%">
                     <asp:TextBox id="tbRedirectAddress" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="150px"></asp:TextBox>&nbsp;
                     <asp:Literal id="litDomain2" runat="server"></asp:Literal></TD>
               </TR>
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" align="right">Redirect Messages
                     to:&nbsp;
                  </TD>
                  <TD style="FONT-SIZE: 8pt" align="left">
                     <asp:TextBox id="tbRedirectTo" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="250px"></asp:TextBox>&nbsp;
                  </TD>
               </TR>
               <TR>
                  <TD align="center" colSpan="2">
                     <asp:Button id="btnDoNewRedirect" runat="server" Text="Add New Redirect"></asp:Button>
                     <asp:Button id="btnDoEditRedirect" runat="server" Text="Save Changes"></asp:Button></TD>
               </TR>
            </TABLE>
         </DIV>
      </DIV>
   </asp:panel><asp:panel id="pnlCatchall" runat="server" Visible="False">
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table200" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Edit&nbsp;Catchall Address:&nbsp;
                     <asp:LinkButton id="btnHelpCatchallFromCatchall" runat="server" Font-Size="8pt">What's This?</asp:LinkButton></TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:Hyperlink id="btnCancelCatchall" runat="server">Cancel</asp:Hyperlink></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <TABLE id="Table300" cellSpacing="10" cellPadding="0" width="600" align="center" border="0">
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" vAlign="top" align="right" width="30%">&nbsp;&nbsp;&nbsp;
                     Address: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px" width="70%">&nbsp;
                     <asp:DropDownList id="selCatchall" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"></asp:DropDownList></TD>
               </TR>
               <TR>
                  <TD align="center" colSpan="2">
                     <asp:Button id="btnDoEditCatchall" runat="server" Text="Save Changes"></asp:Button></TD>
               </TR>
            </TABLE>
         </DIV>
      </DIV>
   </asp:panel><asp:panel id="pnlFilter" runat="server" Visible="False">
      <DIV class="bodyBox" ms_positioning="FlowLayout">
         <DIV class="boxHeader" ms_positioning="FlowLayout">
            <TABLE id="Table2000" cellSpacing="0" cellPadding="0" width="100%" border="0">
               <TR>
                  <TD style="FONT-SIZE: 14px">Add&nbsp;Catchall Filter:&nbsp;
                     <asp:LinkButton id="btnHelpFilterFromFilter" runat="server" Font-Size="8pt">What's This?</asp:LinkButton></TD>
                  <TD style="FONT-SIZE: 8pt" align="right">
                     <asp:Hyperlink id="btnCancelFilter" runat="server">Cancel</asp:Hyperlink></TD>
               </TR>
            </TABLE>
         </DIV>
         <DIV style="PADDING-RIGHT: 4px; PADDING-LEFT: 4px; PADDING-BOTTOM: 14px; WIDTH: 96%; PADDING-TOP: 4px; BACKGROUND-COLOR: #ffffff"
            ms_positioning="FlowLayout">
            <TABLE id="Table3000" cellSpacing="10" cellPadding="0" width="600" align="center" border="0">
               <TR>
                  <TD style="FONT-SIZE: 12px; PADDING-TOP: 2px" vAlign="top" align="right" width="30%">&nbsp;&nbsp;&nbsp;
                     Address: &nbsp;</TD>
                  <TD style="FONT-WEIGHT: bold; FONT-SIZE: 12px" width="70%">&nbsp;
                     <asp:TextBox id="tbNewFilter" runat="server" Font-Size="12px" Font-Names="Tahoma,Arial,Helvetica,Sans-Serif"
                        Width="150px"></asp:TextBox>&nbsp;
                     <asp:Literal id="litDomain3" runat="server"></asp:Literal></TD>
               </TR>
               <TR>
                  <TD align="center" colSpan="2">
                     <asp:Button id="btnDoAddFilter" runat="server" Text="Add Filter"></asp:Button></TD>
               </TR>
            </TABLE>
         </DIV>
      </DIV>
   </asp:panel></div>




Now, if you create a new page in your web project, just drag that control from Solution explorer onto the blank page. Set the page as your start page.

If you set the DomainName variable to something like, "test4.com" and then create (in ME) Postoffice "test4.com", in that postoffice create Domain "test4.com", you should have a little test domain. Do this before you run the web app obviously.

Run the app, play with your settings, periodically check the MMC to verify properties are being set correctly.

You can add this control to any project either by creating it again, or creating a reference. I am going to create it again, because my web app project was just for development. In your final project, which might be something like "AdminApp", you would have a page with your style or theme made for an Email Manage page. Drag the control into the table cell or div (or whatever) where you want the email app to appear. Be sure to include a reference to the ClassLibrary (SWMail, or whatever) in your Admin project.

If you don't use Visual Studio, alot of this won't make sense, but you can still make it work (in theory :wink: ).

Have fun, I think I mentioned everything, but I'm sure I forgot something, post questions...

Tim

stpeteluis
Posts: 8
Joined: Thu Jun 24, 2004 6:53 pm

.NET Code

Postby stpeteluis » Wed Aug 11, 2004 6:57 pm

Tim,
Looks like you've done an amazing job with your .NET app. Congrats.

I tried to "copy" your code and run it but failed. Is there any chance you can email me a copy in a zip file? I think it would be easier than trying to gruess what went wrong.

thanks in advance.
Luis Cabrera
luis@kreko.com

KevinRHurst
Posts: 14
Joined: Thu Oct 07, 2004 5:13 pm
Location: Albuquerque, NM, USA
Contact:

Postby KevinRHurst » Thu Oct 07, 2004 10:09 pm

Tim,

Think I could have a copy also?

thanks!
Kevin R Hurst

Frunder Studios
Albuquerque, NM
87120-1023

www.frunder.com
____________________

kinda like thunder...

sangheraajit
Posts: 2
Joined: Mon Jul 27, 2009 11:24 am

Re: .Net

Postby sangheraajit » Wed Sep 02, 2009 2:21 pm

Hello,
Can you give the working copy of project


Tim wrote:OK, for those of you that are looking for it, a simple way to manage MailEnable from .Net

A few disclaimers (in no particular order):

It was made to my specs, so each postoffice needs to be set up so that postoffice name = domain name and 1 domain per postoffice.
In otherwords postoffice name = domain.ext, with one domain (name = domain.ext)
This isn't the way MailEnable recommends to do it, but it is a simple way to do it if you allow your users to administer there own domains.

Also, at the top of the vb codebehind for the control (see below) is a string variable called DomainName. You will need to set this onPageLoad to the correct domain. (I'm going to strip it from the url used to access the page after authentication)

You will need to recreate some stuff (references, classes, etc., I'm just posting the code), see below for some instructions and tips.

The identity you are running your web app as needs rights to Mail Enable\Config and Mail Enable\Postoffices.

Make sure you Rename the DEFAULT.MAI message in Mail Enable\Config\Postoffices and in existing postoffice directories below that if you don't want the default mail message.

This code has been tested, but don't use it on a production server until you are sure it works the way you want.

The class uses an xml config file (see below for more info) for keeping track of some additional stuff (and simplify things, and so as not to rely to heavily on COM objects), you will have to manually make it for existing domains, and make sure existing domains follow the one-to-one postoffice to domain rule (see above)

I didn't plan on sharing this, it was a quick job, and I started just by fooling around, so there are some redundancies, poor naming conventions, very little commenting, etc., it is what it is.

If you improve on it, or find a bug, post here to let me know, or email me at tpkling at yahoo.com.


Some instructions:

This is the blank config file:

Code: Select all

<?xml version="1.0" ?>
<domain>
<name />
<boxes>5</boxes>
<redirects>10</redirects>
<filters>10</filters>
<limit>10240</limit>
<catchall />
</domain>

Place it in the Mail Enable\Config\Postoffices dir (as "config.xml"), it will be copied to new domains the first time they are accessed.
You'll see what the values do if you successfully run the page.
"mailbox" nodes are added to this file as mailboxes are created, if you need to recreate this for an existing domain, experiment on a new domain and you will see how they work.
Domain config files are stored as "Mail Enable\Config\Postoffices\domain.ext\config.xml".

Next, create a blank solution.

Two projects will be added to it:
One is a class library, mine is called "SWMail", you can call it whatever you want, but you will need to change some code if you change the name.
The second is a Web App, mine is called "SWMailDev", this one doesn't really matter what you call it.

The class library is what does the ditry work. You will need to add two new items (classes) to it (Domain.vb and Validator.vb). Reference MEAOPO.dll, MEAOAM.dll, and MEAOAU.dll in this project!



Validator.vb Source:

Code: Select all

Imports System.Text.RegularExpressions

Public Class Validator
    Dim _Valid As Boolean
    Dim _Type As ValidateType.ValidateFor
    Dim _Err As String
    Public ReadOnly Property IsValid() As Boolean
        Get
            Return _Valid
        End Get
    End Property
    Public ReadOnly Property ErrorMessage() As String
        Get
            Return _Err
        End Get
    End Property
    Public Sub New(ByVal ValidatorType As ValidateType.ValidateFor)
        _Valid = False
        _Type = ValidatorType
    End Sub
    Public Sub Validate(ByVal s As String)
        Select Case _Type
            Case ValidateType.ValidateFor.Address
                Dim m As Match = Regex.Match(s, "^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$")
                If m.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Invalid email format."
                End If
            Case ValidateType.ValidateFor.AddressName
                Dim m As Match = Regex.Match(s, "[A-Za-z0-9][A-Za-z0-9\.\-_]{0,30}[A-Za-z0-9]")
                Dim m2 As Match = Regex.Match(s, "[A-Za-z0-9]")
                If m.ToString = s Or m2.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Addresses need to be at least one letter or digit,<br>and can only contain letters, numbers, or the charcters:  period (.), dash (-), or underscore (_).<br>They can only have a maximum of 32 charcters."
                End If
            Case Else
                _Err = "Error:  Wrong number of arguments or wrong validator type."
        End Select
    End Sub
    Public Sub Validate(ByVal s As String, ByVal c As String)
        If _Type = ValidateType.ValidateFor.Password Then
            If s = c Then
                Dim m As Match = Regex.Match(s, "[0-9A-Za-z]{6,20}")
                If m.ToString = s Then
                    _Valid = True
                Else
                    _Err = "Passwords should only contain 6-20 letters and/or numbers."
                End If
            Else
                _Err = "Passwords do not match, try again."
            End If
        Else
            _Err = "Error:  Wrong number of arguments or wrong validator type."
        End If
    End Sub
    Public Class ValidateType
        <FlagsAttribute()> _
        Enum ValidateFor
            Address = 1
            AddressName = 2
            Password = 4
        End Enum

    End Class
End Class



Domain.vb is more complex and includes several classes:

Code: Select all


Imports System.Xml
Imports System.IO


Public Class Domain

#Region " Private Members "

    Private Const MEPath As String = "C:\Program Files\Mail Enable\Config" 'path in mailenable class of mailbox class is independent of this
    Private _ConfigPath As String
    Private _Xml As XmlNode
    Private _Limit As Integer
    Private Mailboxes As Mailbox()

#End Region

#Region " Public Properties "

    Public ReadOnly Property Name() As String
        Get
            Return _Xml.SelectSingleNode("name").InnerText
        End Get
    End Property

    Public ReadOnly Property CountFilters() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Filter & """]").Count
        End Get
    End Property

    Public ReadOnly Property CountRedirects() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Redirect & """]").Count
        End Get
    End Property

    Public ReadOnly Property CountBoxes() As Integer
        Get
            Return _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.Box & """]").Count + _Xml.SelectNodes("mailbox[@type=""" & Mailbox.MailboxType.Types.DropForward & """]").Count
        End Get
    End Property

    Public ReadOnly Property MaxBoxes() As Integer
        Get
            Return _Xml.SelectSingleNode("boxes").InnerText
        End Get
    End Property

    Public ReadOnly Property MaxRedirects() As Integer
        Get
            Return _Xml.SelectSingleNode("redirects").InnerText
        End Get
    End Property

    Public ReadOnly Property MaxFilters() As Integer
        Get
            Return _Xml.SelectSingleNode("filters").InnerText
        End Get
    End Property

    Public Property Catchall() As String
        Get
            Return _Xml.SelectSingleNode("catchall").InnerText.Trim
        End Get
        Set(ByVal Value As String)
            Try
                If _Xml.SelectSingleNode("catchall").InnerText.Trim = "" Then
                    Dim meInterface As New Mailbox.MailEnable(Me.Name)
                    meInterface.EnableCatchall(Value)
                Else
                    If Value = "" Then
                        Dim meInterface As New Mailbox.MailEnable(Me.Name)
                        meInterface.DisableCatchall(_Xml.SelectSingleNode("catchall").InnerText.Trim)
                    Else
                        Dim meInterface As New Mailbox.MailEnable(Me.Name)
                        meInterface.EditCatchall(_Xml.SelectSingleNode("catchall").InnerText.Trim, Value)
                    End If
                End If
                _Xml.SelectSingleNode("catchall").InnerText = Value
                SaveXMLOnly()
            Catch ex As Exception
                'something went wrong
            End Try
        End Set
    End Property

    Public ReadOnly Property CatchallEnabled() As Boolean
        Get
            If _Xml.SelectSingleNode("catchall").InnerText.Trim = "" Then
                Return False
            Else
                Return True
            End If
        End Get
    End Property

#End Region

#Region " Public Constructor "

    Public Sub New(ByVal domain As String)
        _ConfigPath = MEPath & "\Postoffices" & domain & "\config.xml"
        If Not File.Exists(_ConfigPath) Then
            Dim tempdoc As New XmlDocument
            tempdoc.Load(MEPath & "\Postoffices\config.xml")
            tempdoc.DocumentElement.SelectSingleNode("name").InnerText = domain
            tempdoc.Save(_ConfigPath)
        End If
        Dim doc As New XmlDocument
        doc.Load(_ConfigPath)
        _Xml = doc.DocumentElement
        _Limit = _Xml.SelectSingleNode("limit").InnerText.Trim

        Dim i As Integer = -1
        ReDim Mailboxes(_Xml.SelectNodes("mailbox").Count - 1)
        For Each mb As XmlNode In _Xml.SelectNodes("mailbox")
            i += 1
            Mailboxes(i) = New Mailbox(domain, mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            Mailboxes(i).Xml = mb
        Next
    End Sub

#End Region

#Region " Public Methods "

    Public Function NewRedirect(ByVal name As String, ByVal toaddr As String) As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Redirect, toaddr)
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function NewFilter(ByVal name As String) As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Filter)
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function NewMailbox(ByVal name As String, ByVal password As String, Optional ByVal forward As String = "") As Boolean
        Try
            If _Xml.SelectSingleNode("mailbox[@name=""" & name & """]") Is Nothing Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                If forward = "" Then
                    m.Add(Mailbox.MailboxType.Types.Box, password)
                Else
                    m.Add(Mailbox.MailboxType.Types.DropForward, password, forward)
                End If
                If m.Save Then
                    ReDim Preserve Mailboxes(Mailboxes.GetUpperBound(0) + 1)
                    Mailboxes(Mailboxes.GetUpperBound(0)) = m
                    If Save() Then Return Sort()
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function EditRedirect(ByVal oldname As String, ByVal name As String, ByVal forward As String) As Boolean
        Try
            Dim existsCheck As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            If existsCheck Is Nothing Or oldname = name Then
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                m.Add(Mailbox.MailboxType.Types.Redirect, forward)
                Dim bFound As Boolean = False
                For Each mb As Mailbox In Mailboxes
                    If mb.Name = oldname Then
                        mb.Read(m.Xml)
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then
                    Dim MEResult As Boolean = False
                    If Me.Catchall = oldname Then
                        Me.Catchall = ""
                        MEResult = m.Edit(oldname)
                        Me.Catchall = name
                    Else
                        MEResult = m.Edit(oldname)
                    End If
                    If MEResult Then
                        If Save() Then Return Sort()
                    End If
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function EditMailbox(ByVal oldname As String, ByVal name As String, ByVal password As String, Optional ByVal forward As String = "") As Boolean
        Try
            Dim existsCheck As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            If existsCheck Is Nothing Or oldname = name Then
                Dim editNode As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & oldname & """]")
                If password = "" Then password = editNode.SelectSingleNode("password").InnerText
                Dim m As New Mailbox(_Xml.SelectSingleNode("name").InnerText, name, _Limit)
                If forward = "" Then
                    m.Add(Mailbox.MailboxType.Types.Box, password)
                Else
                    m.Add(Mailbox.MailboxType.Types.DropForward, password, forward)
                End If
                Dim bFound As Boolean = False
                For Each mb As Mailbox In Mailboxes
                    If mb.Name = oldname Then
                        mb.Read(m.Xml)
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then
                    Dim MEResult As Boolean = False
                    If Me.Catchall = oldname Then
                        Me.Catchall = ""
                        MEResult = m.Edit(oldname)
                        Me.Catchall = name
                    Else
                        MEResult = m.Edit(oldname)
                    End If
                    If MEResult Then
                        If Save() Then Return Sort()
                    End If
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function DeleteMailbox(ByVal name As String) As Boolean
        Try
            Dim Result As Boolean = False
            For Each mb As Mailbox In Mailboxes
                If mb.Name = name Then
                    If mb.Delete() Then
                        Dim deleteNode As XmlNode = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
                        _Xml.RemoveChild(deleteNode)
                        If _Xml.SelectSingleNode("catchall").InnerText = name Then _Xml.SelectSingleNode("catchall").InnerText = ""
                        Result = SaveXMLOnly()
                    End If
                    Exit For
                End If
            Next
            Return Result
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function GetMailboxes(Optional ByVal name As String = "") As Mailbox()
        Dim sSearch As String = "mailbox[(@type=""" & Mailbox.MailboxType.Types.Box & """ or @type=""" & Mailbox.MailboxType.Types.DropForward & """)"
        If name <> "" Then sSearch &= " and @name=""" & name & """"
        sSearch &= "]"
        Return GenericGet(sSearch)
    End Function

    Public Function GetRedirects(Optional ByVal name As String = "") As Mailbox()
        Dim sSearch As String = "mailbox[@type=""" & Mailbox.MailboxType.Types.Redirect & """"
        If name <> "" Then sSearch &= " and @name=""" & name & """"
        sSearch &= "]"
        Return GenericGet(sSearch)
    End Function

    Public Function GetEnabled() As Mailbox()
        Return GenericGet("mailbox[@type=""" & Mailbox.MailboxType.Types.Box & """ or @type=""" & Mailbox.MailboxType.Types.DropForward & """ or @type=""" & Mailbox.MailboxType.Types.Redirect & """]")
    End Function

    Public Function GetFilters() As Mailbox()
        Return GenericGet("mailbox[@type=""" & Mailbox.MailboxType.Types.Filter & """]")
    End Function

#End Region

#Region " Private Functions "

    Private Function GenericGet(ByVal xpathSearch As String) As Mailbox()
        Dim resultslist As XmlNodeList = _Xml.SelectNodes(xpathSearch)
        Dim results As Mailbox()
        ReDim results(resultslist.Count - 1)
        Dim i As Integer = -1
        For Each mb As XmlNode In resultslist
            i += 1
            results(i) = New Mailbox("", mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            results(i).Read(mb)
        Next
        Return results
    End Function

    Private Function SaveXMLOnly() As Boolean
        Try
            Dim doc As New XmlDocument
            doc.LoadXml(_Xml.OuterXml)
            doc.Save(_ConfigPath)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function Save() As Boolean
        Try
            Dim doc As New XmlDocument
            doc.LoadXml(_Xml.OuterXml)
            For Each mbn As XmlNode In doc.DocumentElement.SelectNodes("mailbox")
                doc.DocumentElement.RemoveChild(mbn)
            Next
            For Each mb As Mailbox In Mailboxes
                Dim newNode As XmlNode = doc.ImportNode(mb.Xml, True)
                doc.DocumentElement.AppendChild(newNode)
            Next
            _Xml = doc.DocumentElement
            doc.Save(_ConfigPath)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Function Sort() As Boolean
        Dim i As Integer = -1
        ReDim Mailboxes(_Xml.SelectNodes("mailbox").Count - 1)
        Dim mbList As XmlNodeList = _Xml.SelectNodes("mailbox")
        Dim mbnames As New ArrayList
        For j As Integer = 0 To mbList.Count - 1
            mbnames.Add(mbList.Item(j).Attributes.GetNamedItem("name").InnerText)
        Next
        mbnames.Sort()
        For Each name As String In mbnames
            i += 1
            Dim mb As XmlNode
            mb = _Xml.SelectSingleNode("mailbox[@name=""" & name & """]")
            Mailboxes(i) = New Mailbox(_Xml.SelectSingleNode("name").InnerText, mb.Attributes.GetNamedItem("name").InnerText, _Limit)
            Mailboxes(i).Xml = mb
        Next
        Return Save()
    End Function

#End Region



#Region " Mailbox Class "

    Public Class Mailbox

#Region " Private Members "

        Dim _Postoffice As String
        Dim _Mailbox As String
        Dim _Limit As Integer
        Dim _Password As String
        Dim _RedirectAddress As String
        Dim _RedirectStatus As Integer '0 = no, 1 = forward, 2 = drop and forward
        Dim _Status As Integer ' 0=disabled. 1=enabled
        Dim _Xml As XmlNode

#End Region

#Region " Public Properties "

        Public Property Xml() As XmlNode
            Get
                Return _Xml
            End Get
            Set(ByVal Value As XmlNode)
                _Xml = Value
            End Set
        End Property

        Public ReadOnly Property Name() As String
            Get
                Return _Mailbox
            End Get
        End Property

        Public ReadOnly Property Redirected() As String
            Get
                If _RedirectStatus = 0 Then
                    Return False
                Else
                    Return True
                End If
            End Get
        End Property

        Public Property Password() As String
            Get
                Return _Password
            End Get
            Set(ByVal Value As String)
                _Password = Value
                _Xml.SelectSingleNode("password").InnerText = Value
            End Set
        End Property

        Public ReadOnly Property Redirect() As String
            Get
                Return _RedirectAddress
            End Get
        End Property

        Public ReadOnly Property RedirectHTML() As String
            Get
                If _RedirectAddress <> "" Then
                    Return _RedirectAddress
                Else
                    Return "&nbsp;"
                End If
            End Get
        End Property

#End Region

#Region " Public Constructor "

        Public Sub New(ByVal domain As String, ByVal name As String, ByVal limit As Integer)
            _Postoffice = domain
            _Mailbox = name
            _Limit = limit
        End Sub

#End Region

#Region " Public Methods "

        Public Function Add(ByVal t As MailboxType.Types, Optional ByVal sExtraInfo As String = "", Optional ByVal sExtraInfo2 As String = "") As Boolean
            Dim txml As New XmlDocument
            txml.LoadXml("<mailbox type=""0"" name=""" & _Mailbox & """><password /><redirect /></mailbox>")
            txml.DocumentElement.SetAttribute("type", t)
            Select Case t
                Case MailboxType.Types.Box
                    _Password = sExtraInfo
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("password").InnerText = sExtraInfo
                Case MailboxType.Types.Redirect
                    _Password = "password"
                    _RedirectAddress = sExtraInfo
                    _RedirectStatus = 1
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("redirect").InnerText = sExtraInfo
                Case MailboxType.Types.DropForward
                    _Password = sExtraInfo
                    _RedirectAddress = sExtraInfo2
                    _RedirectStatus = 2
                    _Status = 1
                    txml.DocumentElement.SelectSingleNode("password").InnerText = sExtraInfo
                    txml.DocumentElement.SelectSingleNode("redirect").InnerText = sExtraInfo2
                Case MailboxType.Types.Filter
                    _Password = "password"
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 0
            End Select
            _Xml = txml.DocumentElement
            Return True
        End Function

        Public Sub Read(ByVal xml As XmlNode)
            Dim t As MailboxType.Types = xml.Attributes.GetNamedItem("type").InnerText
            Select Case t
                Case MailboxType.Types.Box
                    _Password = xml.SelectSingleNode("password").InnerText
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 1
                Case MailboxType.Types.Redirect
                    _Password = "password"
                    _RedirectAddress = xml.SelectSingleNode("redirect").InnerText
                    _RedirectStatus = 1
                    _Status = 1
                Case MailboxType.Types.DropForward
                    _Password = xml.SelectSingleNode("password").InnerText
                    _RedirectAddress = xml.SelectSingleNode("redirect").InnerText
                    _RedirectStatus = 2
                    _Status = 1
                Case MailboxType.Types.Filter
                    _Password = "password"
                    _RedirectAddress = ""
                    _RedirectStatus = 0
                    _Status = 0
            End Select
            _Xml = xml
        End Sub

        Public Function Delete() As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.Delete(Me)
        End Function

        Public Function Save() As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.SaveNew(Me)
        End Function

        Public Function Edit(ByVal OldName As String) As Boolean
            Dim MEInterface As New MailEnable
            Return MEInterface.SaveEdit(Me, OldName)
        End Function

#End Region


#Region " MailboxType Enum "

        Public Class MailboxType
            <FlagsAttribute()> _
            Enum Types
                Box = 1
                Redirect = 2
                DropForward = 3
                Filter = 4
            End Enum
        End Class

#End Region

#Region " MailEnable Class "

        Public Class MailEnable

#Region " Private Members "

            Dim _Domain As String
            Private Const MEPath As String = "C:\Program Files\Mail Enable\Postoffices"

#End Region

#Region " Public Constructor "

            Public Sub New(Optional ByVal sDomain As String = "")
                _Domain = sDomain
            End Sub

#End Region

#Region " Public Methods "

            Public Sub EditCatchall(ByVal OldMailbox As String, ByVal Mailbox As String)
                DisableCatchall(OldMailbox)
                EnableCatchall(Mailbox)
            End Sub

            Public Sub EnableCatchall(ByVal Mailbox As String)
                Dim AddressMap As New MEAOAM.AddressMap
                With AddressMap
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:*@" & _Domain & "]"
                    .AddAddressMap()
                End With
            End Sub

            Public Sub DisableCatchall(ByVal Mailbox As String)
                Dim AddressMap As New MEAOAM.AddressMap
                With AddressMap
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:*@" & _Domain & "]"
                    If .GetAddressMap = 1 And .SourceAddress = "[SMTP:*@" & _Domain & "]" Then
                        .EditAddressMap(_Domain, "[SMTP:swstempcatchall@" & _Domain & "]", "[SF:" & _Domain & "/" & Mailbox & "]", "")
                    End If
                End With
                'this is lame...
                Dim AddressMap2 As New MEAOAM.AddressMap
                With AddressMap2
                    .Account = _Domain
                    .DestinationAddress = "[SF:" & _Domain & "/" & Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:swstempcatchall@" & _Domain & "]"
                    If .GetAddressMap = 1 Then
                        .RemoveAddressMap()
                    End If
                End With
            End Sub

            Public Function SaveNew(ByRef parent As Mailbox) As Boolean

                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = parent._Mailbox
                    .Limit = parent._Limit
                    .RedirectAddress = "[SMTP:" & parent._RedirectAddress & "]"
                    .RedirectStatus = parent._RedirectStatus
                    .Status = parent._Status
                End With
                If MEMailbox.AddMailbox = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .Description = ""
                    .Password = parent._Password
                    .Rights = "USER"
                    .Status = parent._Status
                    .UserName = parent._Mailbox & "@" & parent._Postoffice
                End With
                If MELogin.AddLogin = 0 Then Return False

                Dim sDir As String = MEPath & "" & parent._Postoffice
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "\mailroot"
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "" & parent._Mailbox
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                sDir &= "\inbox"
                If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = "[SMTP:" & parent._Mailbox & "@" & parent._Postoffice & "]"
                End With
                If MEAddressMap.AddAddressMap = 0 Then Return False

                Return True

            End Function

            Public Function SaveEdit(ByRef parent As Mailbox, ByVal oldname As String) As Boolean
                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = oldname
                    .Limit = -1
                    .RedirectAddress = ""
                    .RedirectStatus = -1
                    .Status = -1
                End With
                '               If MEMailbox.GetMailbox = 0 Then Return False
                If MEMailbox.EditMailbox(parent._Postoffice, parent._Mailbox, "[SMTP:" & parent._RedirectAddress & "]", parent._RedirectStatus, parent._Status, parent._Limit, MEMailbox.Size) = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .Description = ""
                    .Password = ""
                    .Rights = "USER"
                    .Status = -1
                    .UserName = oldname & "@" & parent._Postoffice
                End With
                '                If MELogin.GetLogin = 0 Then Return False
                If MELogin.EditLogin(parent._Mailbox & "@" & parent._Postoffice, parent._Status, parent._Password, parent._Postoffice, MELogin.Description, MELogin.LoginAttempts, MELogin.LastAttempt, MELogin.LastSuccessfulLogin, "USER") = 0 Then Return False

                If oldname <> parent._Mailbox Then
                    Dim sDir As String = MEPath & "" & parent._Postoffice
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    sDir &= "\mailroot"
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    Dim sNewDir As String = sDir & "" & parent._Mailbox
                    sDir &= "" & oldname
                    If Not Directory.Exists(sDir) Then Directory.CreateDirectory(sDir)
                    Directory.Move(sDir, sNewDir)
                    sNewDir &= "\inbox"
                    If Not Directory.Exists(sNewDir) Then Directory.CreateDirectory(sNewDir)
                End If

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & oldname & "]"
                    .Scope = ""
                    .SourceAddress = ""
                End With
                If MEAddressMap.EditAddressMap(parent._Postoffice, "[SMTP:" & parent._Mailbox & "@" & parent._Postoffice & "]", "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]", MEAddressMap.Scope) = 0 Then Return False

                Return True

            End Function

            Public Function Delete(ByRef parent As Mailbox, Optional ByVal RemoveDirectory As Boolean = True) As Boolean

                Dim MEMailbox As New MEAOPO.Mailbox
                With MEMailbox
                    .Postoffice = parent._Postoffice
                    .Mailbox = parent._Mailbox
                    .Limit = -1
                    .RedirectAddress = ""
                    .RedirectStatus = -1
                    .Status = -1
                End With
                If MEMailbox.RemoveMailbox = 0 Then Return False

                Dim MEAddressMap As New MEAOAM.AddressMap
                With MEAddressMap
                    .Account = parent._Postoffice
                    .DestinationAddress = "[SF:" & parent._Postoffice & "/" & parent._Mailbox & "]"
                    .Scope = ""
                    .SourceAddress = ""
                End With
                If MEAddressMap.RemoveAddressMap = 0 Then Return False

                Dim MELogin As New MEAOAU.Login
                With MELogin
                    .Account = parent._Postoffice
                    .LastAttempt = -1
                    .LastSuccessfulLogin = -1
                    .LoginAttempts = -1
                    .Password = ""
                    .Rights = ""
                    .Status = -1
                    .UserName = parent._Mailbox & "@" & parent._Postoffice
                End With
                If MELogin.RemoveLogin = 0 Then Return False

                If RemoveDirectory Then
                    Dim sDir As String = MEPath & "" & parent._Postoffice & "\mailroot" & parent._Mailbox
                    If Directory.Exists(sDir) Then Directory.Delete(sDir, True)
                End If

                Return True

            End Function

#End Region

        End Class 'MailEnable

#End Region

    End Class 'Mailbox

#End Region

End Class ' Domain








In the Web App Project, reference your Class library (SWMail).

Now, in the web app project we are going to create a new user control.
Call it "EmailApp.ascx"
Heres the code behind:(EmailApp.ascx.vb)
[code]

Public Class EmailApp
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents litErrorMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlError As System.Web.UI.WebControls.Panel
Protected WithEvents litWarningMessage As System.Web.UI.WebControls.Literal
Protected WithEvents hlContinue As System.Web.UI.WebControls.HyperLink
Protected WithEvents pnlWarning As System.Web.UI.WebControls.Panel
Protected WithEvents litSuccessMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlSuccess As System.Web.UI.WebControls.Panel
Protected WithEvents litHelpMessage As System.Web.UI.WebControls.Literal
Protected WithEvents pnlHelp As System.Web.UI.WebControls.Panel
Protected WithEvents lblCountBoxes As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxBoxes As System.Web.UI.WebControls.Label
Protected WithEvents btnNewEmail As System.Web.UI.WebControls.LinkButton
Protected WithEvents litMailboxList As System.Web.UI.WebControls.Literal
Protected WithEvents lbHelpRedirect As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblCountRedirects As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxRedirects As System.Web.UI.WebControls.Label
Protected WithEvents lbNewRedirect As System.Web.UI.WebControls.LinkButton
Protected WithEvents litRedirectList As System.Web.UI.WebControls.Literal
Protected WithEvents pnlDefault As System.Web.UI.WebControls.Panel
Protected WithEvents lblEmailAction As System.Web.UI.WebControls.Label
Protected WithEvents btnCancelEmail As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain1 As System.Web.UI.WebControls.Literal
Protected WithEvents tbPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents lblLeaveBlank As System.Web.UI.WebControls.Label
Protected WithEvents tbConfirmPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDoNewEmail As System.Web.UI.WebControls.Button
Protected WithEvents btnDoSaveEmail As System.Web.UI.WebControls.Button
Protected WithEvents cbDropAndForward As System.Web.UI.WebControls.CheckBox
Protected WithEvents tbDropAndForward As System.Web.UI.WebControls.TextBox
Protected WithEvents lbHelpDropAndForward As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlEmail As System.Web.UI.WebControls.Panel
Protected WithEvents lblRedirectAction As System.Web.UI.WebControls.Label
Protected WithEvents lbHelpRedirect2 As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnCancelRedirect As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbRedirectAddress As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain2 As System.Web.UI.WebControls.Literal
Protected WithEvents tbRedirectTo As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDoNewRedirect As System.Web.UI.WebControls.Button
Protected WithEvents btnDoEditRedirect As System.Web.UI.WebControls.Button
Protected WithEvents pnlRedirect As System.Web.UI.WebControls.Panel
Protected WithEvents lblCountFilters As System.Web.UI.WebControls.Label
Protected WithEvents lblMaxFilters As System.Web.UI.WebControls.Label
Protected WithEvents litFilterList As System.Web.UI.WebControls.Literal
Protected WithEvents litCatchallOutput As System.Web.UI.WebControls.Literal
Protected WithEvents btnAddFilter As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlCatchallOn As System.Web.UI.WebControls.Panel
Protected WithEvents btnHelpCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnEditCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnHelpFilters As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlCatchall As System.Web.UI.WebControls.Panel
Protected WithEvents btnCancelCatchall As System.Web.UI.WebControls.HyperLink
Protected WithEvents btnHelpCatchallFromCatchall As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnDoEditCatchall As System.Web.UI.WebControls.Button
Protected WithEvents selCatchall As System.Web.UI.WebControls.DropDownList
Protected WithEvents btnHelpFilterFromFilter As System.Web.UI.WebControls.LinkButton
Protected WithEvents pnlFilter As System.Web.UI.WebControls.Panel
Protected WithEvents btnCancelFilter As System.Web.UI.WebControls.HyperLink
Protected WithEvents tbNewFilter As System.Web.UI.WebControls.TextBox
Protected WithEvents litDomain3 As System.Web.UI.WebControls.Literal
Protected WithEvents btnDoAddFilter As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Dim DomainName As String = "test4.com"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'change that DomainName now!

If Not IsPostBack Then
Select Case Request.QueryString.Get("action")
Case "edit"
Select Case Request.QueryString.Get("type")
Case "redir"
btnCancelRedirect.NavigateUrl = Request.Path
litDomain2.Text = "@" & DomainName
lblRedirectAction.Text = "Edit"
btnDoNewRedirect.Visible = False
btnDoEditRedirect.Visible = True
pnlDefault.Visible = False
pnlRedirect.Visible = True

Dim d As New SWMail.Domain(DomainName)
Dim mb As SWMail.Domain.Mailbox()
mb = d.GetRedirects(Request.QueryString.Get("name"))
If mb.GetLength(0) = 1 Then
tbRedirectAddress.Text = mb(0).Name
Session.Item("oldname") = mb(0).Name
Session.Item("oldredir") = mb(0).Redirect
tbRedirectTo.Text = mb(0).Redirect
Else
GoDefault()
End If

Case Else
litDomain1.Text = "@" & DomainName
lblEmailAction.Text = "Edit"
btnCancelEmail.NavigateUrl = Request.Path
pnlDefault.Visible = False
pnlEmail.Visible = True
btnDoNewEmail.Visible = False
btnDoSaveEmail.Visible = True
lblLeaveBlank.Visible = True
Dim d As New SWMail.Domain(DomainName)
Dim mb As SWMail.Domain.Mailbox()
mb = d.GetMailboxes(Request.QueryString.Get("name"))
If mb.GetLength(0) = 1 Then
tbEmail.Text = mb(0).Name
Session.Item("oldname") = mb(0).Name
Session.Item("oldredir") = mb(0).Redirect
cbDropAndForward.Checked = mb(0).Redirected
tbDropAndForward.Text = mb(0).Redirect
Else
GoDefault()
End If
End Select

Case "help"
Select Case Request.QueryString.Get("topic")
Case "copyto"
ThrowHelp("You have the option to automatically forward messages sent to you to another email address.<br>IMPORTANT: This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to forward all messages to another email, <i>and don't plan on checking this one</i>, use a <i>redirect</i> address instead.")
Case "filter"
btnHelpFilters_Click(sender, e)
Case "catchall"
btnHelpCatchall_Click(sender, e)
End Select
GoDefault()
Case "delete"
If Request.QueryString.Get("confirm") = "true" Then
DeleteBox(Request.QueryString.Get("name"))
Else
Select Case Request.QueryString.Get("type")
Case "filter"
DeleteBox(Request.QueryString.Get("name"))
Case "redir"
ThrowWarning("Are you sure you want to delet this redirect: ""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""?<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
Case Else
ThrowWarning("If you delete this email address (""<b>" & Request.QueryString.Get("name") & "@" & DomainName & "</b>""), all settings and messages that are currently on the server will be deleted.<br>You may choose to continue by clicking the link below, or <a href=""" & Request.Path & """ style=""color:#cc0000;font-weight:bold;"">click here to cancel</a>.", Request.RawUrl & "&confirm=true")
End Select
GoDefault()
End If
Case Else
GoDefault()
End Select
Else
End If
End Sub

Public Sub DeleteBox(ByVal name As String)
Dim d As New SWMail.Domain(DomainName)
'Throw error first, it won't show up if things go ok...
ThrowError("Mailbox deletion failed. Try again or contact support.")
GoDefault(Not d.DeleteMailbox(name))
End Sub
Public Sub InitBoxes()
Dim d As New SWMail.Domain(DomainName)
lblMaxBoxes.Text = d.MaxBoxes
lblCountBoxes.Text = d.CountBoxes
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetMailboxes
If mbs.GetLength(0) > 0 Then
litMailboxList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litMailboxList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Forwarded To:&nbsp;&nbsp;<a style=""font-size:8pt;font-weight:normal;"" href=""" & Request.Path & "?action=help&topic=copyto"">What's This?</a></td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litMailboxList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell(mb.RedirectHTML, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
"</tr>"
Next
litMailboxList.Text &= "</table>"
Else
litMailboxList.Text = "&nbsp;&nbsp;There are no addresses defined at this time."
End If
End Sub
Public Sub InitRedirects()
Dim d As New SWMail.Domain(DomainName)
lblMaxRedirects.Text = d.MaxRedirects
lblCountRedirects.Text = d.CountRedirects
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetRedirects
If mbs.GetLength(0) > 0 Then
litRedirectList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litRedirectList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address:</td><td class=lineHeader>Redirected To:</td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litRedirectList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell(mb.RedirectHTML, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&type=redir&name=" & mb.Name & """>Delete</a>&nbsp;&nbsp;&nbsp;<a href=""" & Request.Path & "?action=edit&type=redir&name=" & mb.Name & """>Edit</a>", BGGrey, "", "L") & _
"</tr>"
Next
litRedirectList.Text &= "</table>"
Else
litRedirectList.Text = "&nbsp;&nbsp;There are no redirect addresses defined at this time."
End If
End Sub
Public Sub InitCatchall()
Dim d As New SWMail.Domain(DomainName)
If d.CatchallEnabled Then
litCatchallOutput.Text = "&nbsp;&nbsp;Catchall <b><i>IS</i></b> Enabled.<br>" & _
"&nbsp;&nbsp;&nbsp;Catchall address: <b><i>" & d.Catchall & "@" & DomainName & "</i></b>"
Else
litCatchallOutput.Text = "&nbsp;&nbsp;Catchall is <b><i>NOT</i></b> Enabled."
End If

lblMaxFilters.Text = d.MaxFilters
lblCountFilters.Text = d.CountFilters
Dim mbs As SWMail.Domain.Mailbox()
mbs = d.GetFilters
If mbs.GetLength(0) > 0 Then
litFilterList.Text = "<table width=100% cellpadding=0 cellspacing=0>"
litFilterList.Text &= "<tr><td class=lineHeader>&nbsp;</td><td class=lineHeader>Address to filter:</td><td class=lineHeader>Actions:</td></tr>"
Dim BGGrey As Boolean = False
Dim c As Integer = 0
For Each mb As SWMail.Domain.Mailbox In mbs
BGGrey = Not BGGrey
c += 1
litFilterList.Text &= "<tr>" & LineItemCell(c, BGGrey, "30") & _
LineItemCell("<b>" & mb.Name & "</b>@" & DomainName, BGGrey) & _
LineItemCell("<a href=""" & Request.Path & "?action=delete&type=filter&name=" & mb.Name & """>Delete</a>", BGGrey, "", "L") & _
"</tr>"
Next
litFilterList.Text &= "</table>"
Else
litFilterList.Text = "&nbsp;&nbsp;There are no catchall filters defined at this time."
End If
End Sub
Private Function LineItemCell(ByVal text As String, ByVal grey As Boolean, Optional ByVal width As String = "", Optional ByVal little As String = "") As String
Dim r As String = "<td "
If width <> "" Then r &= "width=""" & width & """ "

r &= "class=lineItem" & little & " style=""background-color:#"

If grey Then
r &= "eeeef5"
Else
r &= "ffffff"
End If

r &= ";"">" & text & "</td>"

Return r
End Function

Private Sub btnNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewEmail.Click
Dim d As New SWMail.Domain(DomainName)
If d.MaxBoxes > d.CountBoxes Then
btnCancelEmail.NavigateUrl = Request.Path
lblLeaveBlank.Visible = False
litDomain1.Text = "@" & DomainName
lblEmailAction.Text = "New"
btnDoNewEmail.Visible = True
btnDoSaveEmail.Visible = False
pnlDefault.Visible = False
pnlEmail.Visible = True
Else
ThrowError("You have reached your mailbox limit.<br>Before adding new mailboxes you need to delete current ones or contact support for more information on increasing your limit.")
End If

End Sub

Private Sub btnDoNewEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoNewEmail.Click
Dim sAddress As String = tbEmail.Text.ToLower.Trim
Dim sPassword As String = tbPassword.Text.ToLower.Trim
Dim sCPassword As String = tbConfirmPassword.Text.ToLower.Trim
Dim sRedirect As String = tbDropAndForward.Text.ToLower.Trim

Dim validAddress As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.AddressName)
validAddress.Validate(sAddress)
If validAddress.IsValid Then
Dim validPass As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Password)
validPass.Validate(sPassword, sCPassword)
If validPass.IsValid Then
Dim bRedirect As Boolean = True
If cbDropAndForward.Checked Then
Dim validRedirect As New SWMail.Validator(SWMail.Validator.ValidateType.ValidateFor.Address)
validRedirect.Validate(sRedirect)
bRedirect = validRedirect.IsValid
Else
sRedirect = ""
End If
If bRedirect Then
tbEmail.Text = ""
Dim d As New SWMail.Domain(DomainName)
If d.NewMailbox(sAddress, sPassword, sRedirect) Then
ThrowSuccess("New Mailbox created.")
GoDefault(False, True)
Else
ThrowError("Mailbox creation failed.<br>Please make sure the mailbox name is not in use<br>(by any mailbox, redirect, or filter)<br>and try again, or contact support.")
End If
Else
ThrowError("Mailbox creation failed.<br>Check forwarding email address.")
End If

Else
ThrowError(validPass.ErrorMessage)
End If
Else
ThrowError(validAddress.ErrorMessage)
End If
End Sub

Private Sub GoDefault(Optional ByVal ErrorPanel As Boolean = False, Optional ByVal SuccessPanel As Boolean = False)
pnlError.Visible = ErrorPanel
pnlSuccess.Visible = SuccessPanel
pnlDefault.Visible = True
pnlEmail.Visible = False
pnlRedirect.Visible = False
pnlCatchall.Visible = False
pnlFilter.Visible = False
InitBoxes()
InitRedirects()
InitCatchall()
End Sub
Private Sub ThrowError(ByVal msg As String)
pnlError.Visible = True
litErrorMessage.Text = msg
End Sub
Private Sub ThrowSuccess(ByVal msg As String)
pnlSuccess.Visible = True
litSuccessMessage.Text = msg
End Sub
Private Sub ThrowHelp(ByVal msg As String)
litHelpMessage.Text = msg
pnlHelp.Visible = True
End Sub
Private Sub ThrowWarning(ByVal msg As String, ByVal continue As String)
hlContinue.NavigateUrl = continue
litWarningMessage.Text = msg
pnlWarning.Visible = True
End Sub

Private Sub lbHelpDropAndForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbHelpDropAndForward.Click
ThrowHelp("Check this box to automatically forward messages to any other email address.<br>IMPORTANT: This is the option you need if you would like to use this email address, but want a COPY of all messages sent someplace else.<br>If you would like to

Who is online

Users browsing this forum: No registered users and 2 guests