In my opinion Imail’s Active Directory integration is rudimentary at best. They took the all or nothing approach. The following code is something I wrote to let users logon with their Active Directory account to manage their Distribution Lists. It generates a random password in Imail and then automatically logs them in to the system. The user never knows their Imail password and they think its all connected.
Its also a simple example of HTML form automation with javascript.
Set WshShell = CreateObject( “WScript.Shell” )
‘our imail domain in the registry, this is so we can see if the user exists imailDomain = “your.domain.com” ‘the imail adduser utility. imailAddUser = “C:\Program Files\Ipswitch\IMail\adduser.exe” ‘get the logon username and remove the domain name from it username = replace(request.servervariables(“LOGON_USER”), “NTDomain\”,””,1,1,1) ‘generate a random password password = generatePassword(15) ‘check to see if they have an imail account if AccountExists(username) then ‘change password WshShell.exec imailAddUser & ” -mod -u ” & username & ” -p ” & password ‘write the html frames webpage, We use frames so we can use the onload event. writeframes() else ‘The error message could be better but it does the job. response.write “Your account does not exists” end if ‘*** Functions function AccountExists(username) ‘check to see if the user exists in the imail registry. on error resume next registrykey = WshShell.RegRead( “HKLM\SOFTWARE\Ipswitch\IMail\Domains\” & imailDomain & “\Users\” & username & “\MailAddr”) if err.number <> 0 then AccountExists = false else AccountExists = true end if end function Function generatePassword(passwordLength) ‘some asp function i found on the net to generate a random password. sDefaultChars=”abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789!#${}” iPasswordLength=passwordLength iDefaultCharactersLength = Len(sDefaultChars) Randomize’initialize the random number generator ‘Loop for the number of characters password is to have For iCounter = 1 To iPasswordLength ‘Next pick a number from 1 to length of character set iPickedChar = Int((iDefaultCharactersLength * Rnd) + 1) ‘Next pick a character from the character set using the random number iPickedChar ‘and Mid function sMyPassword = sMyPassword & Mid(sDefaultChars,iPickedChar,1) Next generatePassword = sMyPassword End Function Function rot13(rot13text) ‘some asp function i found on the net to generate a rot13 encrption rot13text_rotated = “” ‘ the function will return this string For i = 1 to Len(rot13text) j = Mid(rot13text, i, 1) ‘ take the next character in the string k = Asc(j) ‘ find out the character code if k >= 97 and k =< 109 then k = k + 13 ‘ a … m inclusive become n … z elseif k >= 110 and k =< 122 then k = k – 13 ‘ n … z inclusive become a … m elseif k >= 65 and k =< 77 then k = k + 13 ‘ A … m inclusive become n … z elseif k >= 78 and k =< 90 then k = k – 13 ‘ N … Z inclusive become A … M end if ‘add the current character to the string returned by the function rot13text_rotated = rot13text_rotated & Chr(k) Next rot13 = rot13text_rotated End Function sub writeFrames() ‘write the html frames and javascript to automate the imail form %> <html> <head> <title> Imail LS Glue </title> <script language=”javascript”> String.prototype.enc = function(){ return this.replace(/[a-zA-Z]/g, function(c){ return String.fromCharCode((c <= “Z” ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c – 26); }); }; function logon() { var s = “<%=rot13(password)%>”; parent.imail.document.form1.txtUserName.value='<%=username%>’; parent.imail.document.form1.txtPassword.value=s.enc(); parent.imail.document.form1.btnLogin.click(); } </script> </head> <frameset rows=”0%,100%” border=”0″ onLoad=”logon();”> <frame src=”blank.html” name=”manager” noresize> <frame src=”/iadmin/login.aspx” name=”imail” noresize> </frameset> </html> <% end sub