Create Mailbox using Alias Mail Domain

Discussion, support and announcements for third party applications that work with MailEnable.
Post Reply
faheemsial
Posts: 1
Joined: Mon Jul 30, 2012 7:02 am

Create Mailbox using Alias Mail Domain

Post by faheemsial »

Hi i am trying to create Mailbox using Alias Mail Domain in VB.Net my code is:

Code: Select all

'I have created following postoffice and domains at backend
'PostOffice = "abc.com"
'Domains= {"abc.com","xyz.com"}

'Passing following arguments in call:
call MailboxAdd_FullEmail("admin@xyz.com","asdfasdf")

Public Function MailboxAdd_FullEmail(ByVal Email As String, ByVal Password As String, Optional ByVal Limit As Long = -1) As Long
                Dim UserName As String, Domain As String
                UserName = Split(Email, "@")(0)
                Domain = Split(Email, "@")(1)
                Dim result As Long
                result = MailboxAdd(Domain, UserName, Limit)
                If result <> 0 Then result = LoginAdd(Domain, UserName, Password)
                If result <> 0 Then result = AddressMapAdd(Domain, UserName, Email)
                MailboxAdd_FullEmail = result
End Function

Public Function MailboxAdd(ByVal Postoffice As String, ByVal UserName As String, Optional ByVal Limit As Long = -1) As Long
                Dim RetVal As Long
                Dim oMailbox As New MailEnable.Administration.Mailbox
                
                With oMailbox
                    .Postoffice = Postoffice

                    .Mailbox = UserName
                    .RedirectAddress = ""
                    .RedirectStatus = 0
                    .Status = 1
                    RetVal = .GetMailbox
                    If RetVal = 0 Then 'create the Mailbox
                        .Limit = Limit
                        RetVal = .AddMailbox()
                    Else 'Mailbox already exists.
                        RetVal = -1
                    End If
                End With
                MailboxAdd = RetVal
End Function

Public Function LoginAdd(ByVal Postoffice As String, ByVal UserName As String, ByVal Password As String) As Long
                Dim RetVal As Long
                Dim AuthorityLogin As New MailEnable.Administration.Login
                With AuthorityLogin

                    .Account = Postoffice

                    .UserName = UserName & "@" & Postoffice
                    .Status = 1
                    .Description = ""
                    .Host = ""
                    .Rights = "USER"
                    RetVal = .GetLogin()
                    If RetVal = 0 Then 'create the login
                        .Password = Password
                        RetVal = .AddLogin()
                    Else 'login already exists.
                        RetVal = -1
                    End If
                End With
                LoginAdd = RetVal
End Function

Public Function AddressMapAdd(ByVal Postoffice As String, ByVal UserName As String, ByVal Email As String) As Long
                Dim RetVal As Long
                Dim AddressMap As New MailEnable.Administration.AddressMap
                With AddressMap
                    .Account = Postoffice

                    .DestinationAddress = "[SF:" & Postoffice & "/" & UserName & "]"
                    .Scope = "[SMTP:" & Email & "]"
                    .SourceAddress = "[SMTP:" & Email & "]"

                    'try To get existing email address.
                    RetVal = .GetAddressMap
                    If RetVal = 0 Then 'create a new email address map
                        RetVal = .AddAddressMap()
                    Else 'email address already exists.
                        RetVal = -1
                    End If
                End With
                AddressMapAdd = RetVal
End Function
The result is timeout. I think the problem is as per my code it is trying to find out Postoffice named "xyz.com" which does not exists. how can i get domain while creating the mailbox using "MailEnable.Administration.Mailbox" object??
Please help me modifying the code accordingly.
Thanks,
Faheem
faheemsial@gmail.com

MailEnable
Site Admin
Posts: 4441
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia

Re: Create Mailbox using Alias Mail Domain

Post by MailEnable »

Timeout is normally the result of permissions or a lack of access to the Config directory.
You should first check the event log or consider running processmon (inspecting w3wp process).

As suchm you should either set your code to run under the MailEnableAppPool or make a new app pool with an identity that has access to the MailEnable/Config directory.

This code example may also help as a reference:
http://forum.mailenable.com/viewtopic.php?f=4&t=24015
Regards, Andrew

DericLanza
Posts: 1
Joined: Tue May 15, 2018 9:37 pm

Re: Create Mailbox using Alias Mail Domain

Post by DericLanza »

To create an ALIAS to your PostOffice, you just need to configure the new domain:

Supose that your domain name is mail.mywebdomain.com and you need to get an ALIAS to your accounts, configure the old one mail.myotherdomain.com and it'll be a quiestion if you want to create an ALIAS to your domain. Answer YES, and it's ready.

I hope that helps.

Post Reply