MOTOBIT.COMSome support VBA functions for mailenable mail server

About | IIS monitor | ASP upload | ASP dictionary | UserManager | Pure ASP upload script | Programming tips
Other articles:
Read and write SQL image data, store binary file to sql table. (WSH, Database, Conversion, VBScript)
Work with binary files in VBSscript - read and write local and remote files (WSH, File & data transfer, Functions, VBScript)
Download multiple files in one http request (File & data transfer, VBScript)
Do you like this article?
Please, rate it
and write review!
Rated:
by Aspin.com users
What do you think?
Areas > VBA
Areas > ASP / ASP.Net > Email
Option Explicit

'Add functions - add one email address.
' adds postoffice, mailbox, login And maps email address
Public Function AddFullEmail(ByRef Email As String, _
  ByRef Password As String) As Long
  
  Dim UserName As String, Domain As String
  Domain = Split(Email, "@")(1)
  UserName = Split(Email, "@")(0)

  Dim result As Long
  result = CreatePostOffice(Domain)
  If result <> 0 Then result = AddDoaminToPostOffice(Domain)
  If result <> 0 Then result = AddMailBoxToPostOffice(Domain, UserName)
  If result <> 0 Then result = AddLogin(Domain, UserName, Password)
  If result <> 0 Then result = AddEmail(Domain, UserName, Email)
  AddFullEmail = result
End Function

Function CreatePostOffice(ByRef name As String) As Long
  Dim lResult As Long
  Dim PostOffice As New MEAOPO.PostOffice
  'Set PostOffice = CreateObject("MEAOPO.Postoffice")
  
  With PostOffice
    .name = name
    .Host = name
    .Account = name
    .Status = 1
    'Try To get existing postoffice
    lResult = .GetPostoffice()
    If lResult = 0 Then 'create the postoffice
      lResult = .AddPostoffice()
    Else 'Postoffice already exists.
      lResult = -1
    End If
  End With
  CreatePostOffice = lResult
End Function

'Adds domain To postoffice
Function AddDoaminToPostOffice(ByRef PostOffice As String, _
  Optional ByVal DomainName As String = "") As Long
  If Len(DomainName) = 0 Then DomainName = PostOffice
  
  Dim lResult As Long
  Dim oDomain As New MEAOSM.Domain
  'Set oDomain = CreateObject("MEAOSM.Domain")
  
  With oDomain
    .AccountName = PostOffice
    .DomainName = DomainName
    .Status = 1
    'try To get existing domain.
    lResult = .GetDomain
    If lResult = 0 Then 'create the postoffice
      lResult = .AddDomain
    Else 'Postoffice already exists.
      lResult = -1
    End If
  End With
  AddDoaminToPostOffice = lResult
End Function
          

'Adds mailbox To postoffice
Function AddMailBoxToPostOffice(ByRef PostOffice As String, _
  ByRef UserName As String, _
  Optional ByVal Limit As Long = -1) As Long
  
  
  Dim lResult As Long
  Dim oMailbox As New MEAOPO.Mailbox
  'Set oMailbox = CreateObject("MEAOPO.Mailbox")

  With oMailbox
    .PostOffice = PostOffice
    .Mailbox = UserName
    .RedirectAddress = ""
    .RedirectStatus = 0
    .Status = 1
    
    'try To get existing Mailbox.
    lResult = .GetMailbox
    If lResult = 0 Then 'create the Mailbox
      .Limit = Limit
      lResult = .AddMailbox()
    Else 'Mailbox already exists.
      lResult = -1
    End If
  End With
  AddMailBoxToPostOffice = lResult
End Function
      
      
'Adds Login To postoffice
Function AddLogin(ByRef PostOffice As String, _
  ByRef UserName As String, ByRef Password As String) As Long
  
  
  Dim lResult As Long
  Dim oAUTHLogin As New MEAOAU.Login
  'Set oAUTHLogin = CreateObject("MEAOAU.Login")

  'when we create a mailbox we also create a pop logon
  With oAUTHLogin
    .Account = PostOffice
    .UserName = UserName & "@" & PostOffice
    .Status = 1
    .Description = ""
    .Host = ""
    .Rights = "USER"
    
    'try To get existing login.
    lResult = .GetLogin()
    If lResult = 0 Then 'create the login
      .Password = Password
      lResult = .AddLogin()
    Else 'login already exists.
      lResult = -1
    End If
  End With
  AddLogin = lResult
End Function
      
'Adds domain To postoffice
Function AddEmail(ByRef PostOffice As String, _
  ByRef UserName As String, ByRef Email As String) As Long
  
  Dim lResult As Long
  Dim oAddressMap As New MEAOAM.AddressMap
'  Set oAddressMap = CreateObject("MEAOAM.AddressMap")

  With oAddressMap
    Dim varTemp
    
    .Account = PostOffice
    .DestinationAddress = "[SF:" & PostOffice & "/" & UserName & "]"
    .Scope = "[SMTP:" & Email & "]"
    .SourceAddress = "[SMTP:" & Email & "]"
    
    'try To get existing email address.
    lResult = .GetAddressMap
    If lResult = 0 Then 'create a new email address map
      lResult = .AddAddressMap()
    Else 'email address already exists.
      lResult = -1
    End If
  End With
  AddEmail = lResult
End Function
      





'****************** control functions **********************
'retrieves a password from an email address (username@postoffice)
Public Function GetPassword(ByRef Email As String) As String
  Dim oLogin
  Set oLogin = GetoLogin("" & Split(Email, "@")(1), _
    "" & Split(Email, "@")(0))
  GetPassword = oLogin.Password
End Function

'checks If the login/account is created.
Public Function ExistsLogin(ByRef Email As String) As Boolean
  ExistsLogin = IsObject(GetoLogin("" & Split(Email, "@")(1), _
    "" & Split(Email, "@")(0)))
End Function

'Returns a login object
Function GetoLogin(ByRef PostOffice As String, _
  ByRef UserName As String)
  
  Dim lResult As Long
  Dim oAUTHLogin As New MEAOAU.Login
  'Set oAUTHLogin = CreateObject("MEAOAU.Login")

  With oAUTHLogin
    .Account = PostOffice
    .UserName = UserName & "@" & PostOffice
    .Status = 1
    .Description = ""
    .Host = ""
    .Rights = "USER"
    
    'try To get existing login.
    lResult = .GetLogin()
    If lResult <> 0 Then 'create the login
      Set GetoLogin = oAUTHLogin
    End If
  End With
End Function

'checks If the email address is mapped To an account.
Public Function ExistsEmail(ByRef Email As String) As Boolean
  Dim lResult As Long
  Dim oAddressMap As New MEAOAM.AddressMap
'  Set oAddressMap = CreateObject("MEAOAM.AddressMap")
  
  Dim PostOffice As String
  PostOffice = Split(Email, "@")(1)
  With oAddressMap
    Dim varTemp
    
    .Account = PostOffice
    .SourceAddress = "[SMTP:" & Email & "]"
    
    'try To get existing address.
    lResult = .GetAddressMap
    ExistsEmail = lResult <> 0
  End With
End Function

See also

for 'Some support VBA functions for mailenable mail server' article
Check if a pop3 email account exists in a windows 2003 pop3 serviceLet's you check if a pop3 user email account exists in a windows 2003 pop3 service
Add an email account to a windows 2003 pop3 service using scriptLet's you add pop3 user account to a windows 2003 pop3 service using script (VBScript) or Visual basic from WSH, ASP, office or ASP.Net.

Copyright and use this code

The source code on this page and other samples at http://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
or
2. Link this sample from you page.
<A
 Href="http://www.motobit.com/tips/detpg_mailenable-support/"
 Title="Lets you create postoffice, mailboxes, logins,
	email adresses from VBA or
	VBScript."
>Some support VBA functions for mailenable mail server</A>

© 1996 - 2012 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz


Partner sites: Search Czech Last minute Zajezdy Obsah na mobil Hry na mobil Java Hry Print-shop Affiliate programy

Kurzy: Akcie | Urad prace | Zakony | Zlato | Firmy | Dane


     IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).      ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.
     Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.      ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.
     ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.      Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.
     Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).      ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).
     WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.      HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.
Motobit.com