WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Required files:
EMailBoxInfo.dll
MailSize.htm

; Program Name: Mail Current Mailbox Size
; FileName: EmailStatus.wbt
; Author: Kent Ruddick  Winbatch@npemail.com
; Created: 09/28/04
; Revision: Never
; Description: Grab all users with mailboxes and email them a status email letting them know
;              the size of their mailbox.
; Legal: You are free to use my dll and code in any non-commecial application. You can not sell
;        my dll or code. Please contact winbatch@npemail.com if you have questions.
;        I reserve all rights.
;Version 0.0.0.0
; *** Use at your own Risk!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
Directory = DirGet()
;Directory = "C:\"
; In order to use the dll, you must register the dll on the computer. Use the following script
key=RegExistKey(@REGCLASSES, "CLSID\{FBB298EE-7254-4EA5-8237-5346BCC8E741}")
If key == 1 Then
   ;Message ("Registered", "The DLL is Registered.")
Else
   PathtoDll = StrCat('/s "', Directory, 'EMailBoxInfo.dll"')
   RunHide("regsvr32", PathtoDll)
EndIf

;Let's round off all our numbers so they look good.
Decimals(0)
;Add the two extenders needed for this program
AddExtender("WWADS34I.DLL")
AddExtender("WWPST34I.DLL")

;Our settings for the script. Change these for your environment
ExchangeServer = "" ;FILL THIS IN
DomainName     = "" ;FILL THIS IN

;Mail Settings
;Relay SMTP Server
Relay   = ""  ;FILL THIS IN
;Your email so you can get all the failures and figure out what weird accounts have mailboxes
From    = "WinBatch@npemail.com"
;Creative title..
Subject = "Monthly Mailbox Size Report"

;To store the users and their info
Users = ""

;This may need to be changed. Exchange server is DC so it holds all accounts
sADSIPath = StrCat("LDAP://",ExchangeServer,"/DC=",DomainName,",DC=com")

;Grab paths to people with mailboxes, but are not recipients. Cannot log onto a recipient.
UserPath = dsFindPath(sADSIPath, "(&(ObjectClass=person)(sAMAccountType=805306368))")

;Count them up for enumeration
PathCount = ItemCount(UserPath,@TAB)

;Create a connection to the object
oMapi = CreateObject("EMailBoxInfo.mailinfo")
oMapi.Server = ExchangeServer

;Grab them thar people and their fat mailboxes
For x = 1 To PathCount
   ;A path to each user to get some information we need
   Path = ItemExtract(x,UserPath,@TAB)
   ;Grab the NickName so we can weed out more non-real users, Non-Users will not have a nickname
   Address = dsGetProperty(Path,"mailnickname")
   ;If you don't have a nickname, you are probably not in the address list.
   If Address <> "" Then
      ;We don't need to do the system mail box.
      If !StrIndex(Address,"SystemMailbox",1,@FWDSCAN) Then
         ;Let's not do the Administrator mail box. Add others you wish to skip here.
         If Address <> "Administrator" Then
            ;Grab the Acount name for logon
            SamName = dsGetProperty(Path,"samAccountName")
            ;Grab the email address to send the email to...
            Email = dsGetProperty(Path,"mail")
            ;Log onto their mailbox and get the info
            oMAPI.FillMailInfo(SamName)
            ;Place it in a list so we can work with it.
            If Users == "" Then
               Users = StrCat(oMAPI.Size,",",SamName,",",oMAPI.Count,",",Email)
            Else
               Users = StrCat(Users,@TAB,oMAPI.Size,",",SamName,",",oMAPI.Count,",",Email)
            EndIf
            ;Not sure if needed, but clear the settings
            oMAPI.Size = 0
            oMAPI.Count = 0
         EndIf
      EndIf
   EndIf
Next

;Kill the object
oMapi = 0

;Count up the Users to size an array for sorting.
UserCount = ItemCount(Users,@TAB)

;User Arry from ItemList
UserArray = Arrayize(Users,@TAB)
;Prevent a negative number since subtracting one
Top = Max(0,ArrInfo(UserArray,1)-1)
For i = 0 To (Top)
   Index = i+1
   For j = Index To Top
      ;Greatest will be 0 and Least will be last
      If (ItemExtract(1,UserArray[i],","))  <  (ItemExtract(1,UserArray[j],",")) Then
         Element = UserArray[i]
         UserArray[i] = UserArray[j]
         UserArray[j] = Element
      EndIf
   Next
Next

;Read the pre-made email message
HTMLFile = StrCat(Directory,"MailSize.htm")
HTMLMessage = FileGet(HTMLFile)

;Start Replacing pieces of the email with custom amounts
TipTop = Top + 1
HTMLMessage = StrReplace(HTMLMessage,"xxamountxx", TipTop)

;Everybody gets a message. Loop through entire array
For y = 0 To Top
   ;Copy our message leaving original intact.
   Personal = HTMLMessage
   ;Replace more items in message
   Personal = StrReplace(Personal, "xxnamexx", ItemExtract(2,UserArray[y],","))
   Personal = StrReplace(Personal, "xxrankxx", y+1)
   ;
   size = ItemExtract(1,UserArray[y],",")
   ;Do a small conversion to make it more readable.. and less daunting
   If size > 1024 Then
      Size = size /1024
      If Size > 1024 Then
         Size = Size /1024
         Size = StrCat(size, " MB")
      Else
         Size = "1 MB"
      EndIf
   Else
      size = "0 MB"
   EndIf
   ;Couple more items
   Personal = StrReplace(Personal, "xxsizexx", size)
   Personal = StrReplace(Personal, "xxcountxx", ItemExtract(3,UserArray[y],","))
   ;Make a mail message and send it off
   SendTo = ItemExtract(4,UserArray[y],",")
   kInit(Relay,From,"","","")
   kDest(SendTo,"","")
   kSendText(subject,Personal,"","h")
Next

;Silent uninstall of DLL
PathtoDll = StrCat('/s /u"', Directory, 'EMailBoxInfo.dll"')
RunHide("regsvr32", PathtoDll)



Article ID:   W17232
File Created: 2019:08:14:09:27:32
Last Updated: 2019:08:14:09:27:32