EasyCFM.COM ColdFusion Forums / ASP to CFML / CFOBJECT Help

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: CFOBJECT Help

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

RafaelQ
05-25-2004 @ 9:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 107
Joined: Feb 2004

I have been searching for some tutorials/exmaples of using CFOBJECT and haven't found any except for the macromedia tutorial.

I want to use the mailenable mail server API to add/delete, change passowrds, etc... Their forum has examples using ASP but none using CF.

Here's a code snipplet on changing passwords:

<%
if request.form.count <>
0 then
Set oLogin = CreateObject("MEAOAU.Login")
postoffice = split(request("username"),"@",-1, 1)
oLogin.Account = Postoffice(1)
oLogin.Description = ""
oLogin.Rights = "USER"
oLogin.Status = 1
oLogin.UserName = request("username")
oLogin.getLogin()
ChangeResult = oLogin.EditLogin(request("username"),1,request("NewPassword"),Postoffice(1) , "", 0, 0, 0, "USER")
if changeResult = 1 then
Response.write "Successfully Changed..."
end if
Set oLogin = Nothing
end if
%>
<html>
<head>
<title>Mailenable Password change</title>
</head>
<body>
<form name="submit" action="internal.asp" method="post" >
Username: <input type="text" name="username"><BR>
New Password: <input type="text" name="NewPassword"><BR>
<input type="submit">
<form>
</body>
</html>


And here's sample code on adding a user:

<%
     Option Explicit
     
    Dim lResult
     Dim sErr, sMsg
     Dim sMailRoot
     Dim sTemp
     Dim oSMTPDomain, oFSO, oAddressMap, oMailbox, oAUTHLogin
     
    if len(request("mailbox"))>
0 then

          if len(request("postoffice"))=0 or len(request("password"))=0 then
               sErr = "<BR>You must fill out all details"
          end if
          
          if len(sErr)=0 then
               sMailRoot = "c:\program files\mail enable\POSTOFFICES"
     
               set oMailbox = server.CreateObject("MEAOPO.Mailbox")
               set oAUTHLogin = server.CreateObject("MEAOAU.Login")
    
               With oMailbox
                   .Postoffice = request("postoffice")
                   .Mailbox = request("mailbox")
                   .Limit = -1
                   .RedirectAddress = ""
                   .RedirectStatus = 0
                   .Status = 1
                   lResult = oMailbox.AddMailbox()
               End With
    
               if lResult = 0 then
                    sErr = sErr & "<BR>Could not add mailbox. Make sure it doesn't already exist."
               end if
          
               'when we create a mailbox we also create a pop logon
               With oAUTHLogin
                   .Account = request("postoffice")
                   .Description = ""
                   .Password = request("password")
                   .Rights = "USER"
                   .Status = 1
                   .UserName = request("mailbox") & "@" & request("postoffice")
               End With
                   
               lResult = oAUTHLogin.AddLogin()

               if lResult = 0 then
                    sErr = sErr & "<BR>Could not add password."
               end if
    
               'we have to create the directories as well.. later providers will do this automatically
               set oFSO = server.CreateObject("Scripting.FileSystemObject")
          
               'is the post office there?
               If Not oFSO.FolderExists(sMailRoot & "\" & request("postoffice")) Then
                   oFSO.CreateFolder sMailRoot & "\" & request("postoffice")
               End If
    
               'is the mailroot there?
               If Not oFSO.FolderExists(sMailRoot & "\" & request("postoffice") & "\mailroot") Then
                   oFSO.CreateFolder sMailRoot & "\" & request("postoffice") & "\mailroot"
               End If
    
               If Not oFSO.FolderExists(sMailRoot & "\" & request("postoffice") & "\mailroot\" & request("mailbox")) Then
                   oFSO.CreateFolder sMailRoot & "\" & request("postoffice") & "\mailroot\" & request("mailbox")
               End If
    
               'also create the inbox
               If Not oFSO.FolderExists(sMailRoot & "\" & request("postoffice") & "\mailroot\" & request("mailbox") & "\inbox") Then
                   oFSO.CreateFolder sMailRoot & "\" & request("postoffice") & "\mailroot\" & request("mailbox") & "\inbox"
               End If
    
               Set oSMTPDomain = Server.CreateObject("MEAOSM.Domain")
               Set oAddressMap = Server.CreateObject("MEAOAM.AddressMap")

               'make sure the result view is specified as the default in the scope item properties
    
               'this is a host, so find the accounts and list them
               With oSMTPDomain
                   .AccountName = request("postoffice")
                   .DomainName = ""
                   .Status = -1
                   .DomainRedirectionStatus = -1
                   .DomainRedirectionHosts = ""
               End With
    
               If oSMTPDomain.FindFirstDomain() = 1 Then
                   Do                                     
                       sTemp = "[SMTP:" & request("mailbox") & "@" & oSMTPDomain.DomainName & "]"
                       
                       sMsg = sMsg & "<BR>Added email address: " & request("mailbox") & "@" & oSMTPDomain.DomainName
                       
                       'add this to the file
                       With oAddressMap
                              .Account = request("postoffice")
                              'destination is this mailbox
                              .DestinationAddress = "[SF:" & request("postoffice") & "/" & request("mailbox") & "]"
                              .Scope = ""
                              .SourceAddress = sTemp
                              lResult = .AddAddressMap()
                       End With
                       
                         if lResult = 0 then
                              sErr = sErr & "<BR>Could not add address mapping."
                         end if

                       With oSMTPDomain
                           .AccountName = request("postoffice")
                           .DomainName = ""
                           .Status = -1
                           .DomainRedirectionStatus = -1
                           .DomainRedirectionHosts = ""
                       End With
                   
                   Loop While oSMTPDomain.FindNextDomain() = 1
               else
                    sErr = sErr & "<BR>There are no domains for post office:" & request("postoffice")
               End If
          end if
                    
     end if
         
    
%>
<html>
<body>
<% if len(sMsg)>0 then Response.write sMsg & "<BR>"

     if len(sErr)>0 then
          Response.Write sErr & "<BR>"
     end if
%>
<form method=post action=addmailbox.asp>
Adds a mailbox to a post office. Will create an email
address for each domain configured in the post office.<BR><BR>
Postoffice: <input type=text name=postoffice value='<% =request("postoffice") %>'><BR>
Mailbox name: <input type=text name=mailbox value='<% =request("mailbox") %>'><BR>
Password: <input type=text name=password value='<% =request("password") %>'><BR>
<input type=submit value="Add Mailbox">
</form>
</body>
</html>


I realize this is a HUGE chunk of code. I'm just looking for some direction.

Thanks!


Website Designed and Developed by Pablo Varando.