Windows Solutions, AD, DNS, DHCP, Migration, UPgrade, IIS, SSL, VPN
Karnav Thakar. MCP, MCSA, MCSE, MSITP, CHFI, ECA
Wednesday, 28 July 2021
Monday, 2 July 2018
Asterisk/FreePBX/Elastix add Listen/Whisper/Barge facilities to your PABX
If you have PABX server like Asterisk / Free PBX / Elastix and want to feature to listen / whisper / barge to other calls.
ChanSpy can give you ability to achieve this feature.
So here’s what you can do. If you’re using this as it is, make sure that there are no feature codes using *331 & *332 & *333.
Add below code to extensions_custom.conf. Reload asterisk and you should be able to listen on extension 1001, simply dial *3311001.
[ext-local-custom]
;listen
exten => _*331x.#,1,Macro(user-callerid,)
exten => _*331x.#,n,Answer
exten => _*331x.#,n,NoCDR
exten => _*331x.#,n,Wait(1)
exten => _*331x.#,n,ChanSpy(sip/${EXTEN:4},q)
exten => _*331x.#,n,Hangup
;whisper
exten => _*332x.#,1,Macro(user-callerid,)
exten => _*332x.#,n,Answer
exten => _*332x.#,n,NoCDR
exten => _*332x.#,n,Wait(1)
exten => _*332x.#,n,ChanSpy(sip/${EXTEN:4},qw)
exten => _*332x.#,n,Hangup
;barge
exten => _*333x.#,1,Macro(user-callerid,)
exten => _*333x.#,n,Answer
exten => _*333x.#,n,NoCDR
exten => _*333x.#,n,Wait(1)
exten => _*333x.#,n,ChanSpy(SIP/${EXTEN:4},qB)
exten => _*333x.#,n,Hangup
Now, say there are some extensions like managers, CEO, CIO that you don’t want to be listened on, there are many ways to do it. Easy way to do this, add following code the above set.
Here, no one should be able to listen/whisper/barge on extension 1007’s calls. What this code does is if someone tries to do be naughty, it will simply hangup the call.
;blockaccess
exten => _*3311007,1,Macro(user-callerid,)
exten => _*3311007,n,Hangup
exten => _*3321007,1,Macro(user-callerid,)
exten => _*3321007,n,Hangup
exten => _*3331007,1,Macro(user-callerid,)
exten => _*3331007,n,Hangup
If you are using PJSIP then
change
,n,ChanSpy(sip/${EXTEN:4},qw)
to
,n,ChanSpy(pjsip/${EXTEN:4},qw)
Also you may want to try with password
[from-internal-custom]
exten => 5555,1,Macro(user-callerid)
exten => 5555,2,Authenticate(YOUR PIN like 12345)
exten => 5555,3,Read(SPYNUM,agent-newlocation)
exten => 5555,4,ChanSpy(SIP/${SPYNUM))
ChanSpy can give you ability to achieve this feature.
So here’s what you can do. If you’re using this as it is, make sure that there are no feature codes using *331 & *332 & *333.
Add below code to extensions_custom.conf. Reload asterisk and you should be able to listen on extension 1001, simply dial *3311001.
[ext-local-custom]
;listen
exten => _*331x.#,1,Macro(user-callerid,)
exten => _*331x.#,n,Answer
exten => _*331x.#,n,NoCDR
exten => _*331x.#,n,Wait(1)
exten => _*331x.#,n,ChanSpy(sip/${EXTEN:4},q)
exten => _*331x.#,n,Hangup
;whisper
exten => _*332x.#,1,Macro(user-callerid,)
exten => _*332x.#,n,Answer
exten => _*332x.#,n,NoCDR
exten => _*332x.#,n,Wait(1)
exten => _*332x.#,n,ChanSpy(sip/${EXTEN:4},qw)
exten => _*332x.#,n,Hangup
;barge
exten => _*333x.#,1,Macro(user-callerid,)
exten => _*333x.#,n,Answer
exten => _*333x.#,n,NoCDR
exten => _*333x.#,n,Wait(1)
exten => _*333x.#,n,ChanSpy(SIP/${EXTEN:4},qB)
exten => _*333x.#,n,Hangup
Now, say there are some extensions like managers, CEO, CIO that you don’t want to be listened on, there are many ways to do it. Easy way to do this, add following code the above set.
Here, no one should be able to listen/whisper/barge on extension 1007’s calls. What this code does is if someone tries to do be naughty, it will simply hangup the call.
;blockaccess
exten => _*3311007,1,Macro(user-callerid,)
exten => _*3311007,n,Hangup
exten => _*3321007,1,Macro(user-callerid,)
exten => _*3321007,n,Hangup
exten => _*3331007,1,Macro(user-callerid,)
exten => _*3331007,n,Hangup
If you are using PJSIP then
change
,n,ChanSpy(sip/${EXTEN:4},qw)
to
,n,ChanSpy(pjsip/${EXTEN:4},qw)
Also you may want to try with password
[from-internal-custom]
exten => 5555,1,Macro(user-callerid)
exten => 5555,2,Authenticate(YOUR PIN like 12345)
exten => 5555,3,Read(SPYNUM,agent-newlocation)
exten => 5555,4,ChanSpy(SIP/${SPYNUM))
Wednesday, 5 July 2017
how to remove IMAP Property from Outlook folder
- Get MFCMAPI . If you have 64 bit office, you need 64 bit MFCMAPI.
- Open MFCMAPI, go to Session, Logon
- Select your profile
- Double-click on the affected data store. This should open another windows.
- Expand Root - Mailbox
- Expand Top of Information Store or IPM_Subtree
- Select Inbox
- Look for PR_CONTAINER_CLASS in the right pane, double-click on it.
- Repeat for each folder that was exported from an IMAP data file.
- When you are finished, close the MFCMAPI window, click Session, Logoff on the last MFCMAPI window.
Thursday, 8 October 2015
How to convert a PFX to a seperate .key/.crt file
In this article I’m going to show you the commands you need to convert your .PFX Certificate file to a seperate certificate and keyfile. This article can come in handy when you need to import your certificates on devices like Cisco routers/loadbalancers etc. where you probably need to import the certificates and keyfiles in plain text (unencrypted). My tool of choice (but there might be others) is OpenSSL for Windows, which can be downloaded here
So after you installed OpenSSL you can start it from it’s Bin folder. I’d like to put OpenSSL\Bin in my path so I can start it from any folder. Fire up a command prompt and cd to the folder that contains your .pfx file.
First type the first command to extract the private key:
Now let’s extract the certificate:
Just press enter and your certificate appears.
Now as I mentioned in the intro of this article you sometimes need to have an unencrypted .key file to import on some devices. I probably don’t need to mention that you should be carefully. If you store your unencrypted keypair somewhere on an unsafe location anyone can have a go with it and impersonate for instance a website or a person of your company. So always be extra careful when it comes to private keys! Just throw the unencrypted keyfile away when you’re done with it, saving just the encrypted one.
The command:
In some cases you might be forced to convert your private key to PEM format. You can do so with the following command:
So after you installed OpenSSL you can start it from it’s Bin folder. I’d like to put OpenSSL\Bin in my path so I can start it from any folder. Fire up a command prompt and cd to the folder that contains your .pfx file.
First type the first command to extract the private key:
openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.Now let’s extract the certificate:
openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]
Just press enter and your certificate appears.
Now as I mentioned in the intro of this article you sometimes need to have an unencrypted .key file to import on some devices. I probably don’t need to mention that you should be carefully. If you store your unencrypted keypair somewhere on an unsafe location anyone can have a go with it and impersonate for instance a website or a person of your company. So always be extra careful when it comes to private keys! Just throw the unencrypted keyfile away when you’re done with it, saving just the encrypted one.
The command:
openssl rsa -in [keyfile-encrypted.key] -out [keyfile-decrypted.key]
Again you need to enter an import password. This time you need to enter the new password that you created in step 1. After that you’re done. You decrypted your private key. In the folder you ran OpenSSL from you’ll find the certifcate (.crt) and the two private keys (encrypted and unencrypted).In some cases you might be forced to convert your private key to PEM format. You can do so with the following command:
openssl rsa -in [keyfile-encrypted.key] -outform PEM -out [keyfile-encrypted-pem.key]
Friday, 9 March 2012
Disable Sync Center VIA GPO
An easy way of preventing mobsync.exe from running on system startup.
1) Within your group policy, expand User Configuration 2) Expand Window Settings 3) Expand Security Settings 4) Expand Software Restrictions 5) Double click Additional Rules 6) Right click and click new path rule 7) Add %windir%\system32\mobsync.exe 8.) Follow step 6 again and add %windir%\system32\mobsync.exe
1) Within your group policy, expand User Configuration 2) Expand Window Settings 3) Expand Security Settings 4) Expand Software Restrictions 5) Double click Additional Rules 6) Right click and click new path rule 7) Add %windir%\system32\mobsync.exe 8.) Follow step 6 again and add %windir%\system32\mobsync.exe
Thursday, 19 January 2012
Wordpress installation 5 Minute Super Guide
5 Minute Super Guide:
Main Install
Make sure CentoOS is upto date:
yum update
Install Apache/Mysql/PHP/Unzip/Wget:
yum -y install mysql-server httpd php php-mysql unzip wget
Enable Apache and MySQL
chkconfig httpd on
chkconfig mysqld on
Start Apache and MySQL
/etc/init.d/mysqld start
/etc/init.d/httpd start
Set root password for MySQL (IMPORTANT!)
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='root';
mysql> flush privileges;
Setup WordPress Database
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
mysql> FLUSH PRIVILEGES;
mysql> quit;
Download WordPress
cd /var/www/html
wget http://wordpress.org/latest.zip
Extract WordPress
unzip latest.zip
rm latest.zip
Move WordPress to Root Directory
mv wordpress/* ./
rmdir wordpress/
Give WordPress permissions to write
mkdir wp-content/uploads wp-content/cache
chown apache:apache wp-content/uploads wp-content/cache ./
Open and configure WordPress
http://your-server-ip-or-hostname/
In the Config enter your SQL Username ‘wordpress’ and the password you set earlier.
Click Save and your all done!
Fixes permissions for Permalinks:
chown apache:apache /var/www/html/.htaccess
Let Appache Edit .htaccess for Permalinks:
nano /etc/httpd/conf/httpd.conf
And edit the Section:
<Directory "/var/www/html">
And Change Allow ovride to:
AllowOverride ALL
Enable Multiple Sites:
define('WP_ALLOW_MULTISITE', true);
Tuesday, 10 January 2012
Automated email notification for Windows server 2008 backup
Hello All,
Please download attached zip file and extract it to c: drive and follow instrustions from folder script\HowtouseWindowsServerBackupAlerts
emailnotificationforWindowsserver2008backup
Please download attached zip file and extract it to c: drive and follow instrustions from folder script\HowtouseWindowsServerBackupAlerts
emailnotificationforWindowsserver2008backup
Tuesday, 15 November 2011
Hide Local computer drives
You can instruct Explorer to not display a drive(s) in the My Computer display. When enabled, this policy removes the icons representing the selected disk drives from My Computer, Windows Explorer, and My Network Places and from Common Dialogs. Note that the registry key is Policies\Explorer.
For example, you create partition E: and use it exclusively for NT's pagefile. To prevent a (possibly ignorant) user from browsing to that partition and deleting files that should not be deleted, apply the following Windows NT / Windows 2000 Registry hack :
Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Windows\CurrentVersio…
Name: NoDrives
Type: REG_DWORD
Value: To calculate the value, add together the numbers for the drives you want to hide, using the formula: A=1, B=2, C=4, D=8, E=16, F=32, G=64, and so forth. To hide D: & E:, the value would be 8+16=24.
To use system policies to hide drives:
http://support.microsoft.com/support/kb/…
Online tool for calculating the Mask for the NoDrives Registry key, it calculates the mask for any drive combination:
http://www.wisdombay.com/hidedrive/
For example, you create partition E: and use it exclusively for NT's pagefile. To prevent a (possibly ignorant) user from browsing to that partition and deleting files that should not be deleted, apply the following Windows NT / Windows 2000 Registry hack :
Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Windows\CurrentVersio…
Name: NoDrives
Type: REG_DWORD
Value: To calculate the value, add together the numbers for the drives you want to hide, using the formula: A=1, B=2, C=4, D=8, E=16, F=32, G=64, and so forth. To hide D: & E:, the value would be 8+16=24.
To use system policies to hide drives:
http://support.microsoft.com/support/kb/…
Online tool for calculating the Mask for the NoDrives Registry key, it calculates the mask for any drive combination:
http://www.wisdombay.com/hidedrive/
Saturday, 12 November 2011
Automated email notification for Windows backup
The native backup utility found on Windows servers is one cool application that has saved many SMBs real cash! Apart from fulfilling its main functionality, it is found to be very reliable and effective. Problems arise when extra features are required such as, backing up to external storage devices and/or utilizing advanced backup features! One useful feature that is standard in purchasable applications is email notification of backup jobs. The script below gives you that functionality!!!! It’s free and simple to implement!!!!
The implementation steps of the script are as follows:
1. Create a backup job using Windows backup – Start/All Programs/Accessories/System Tools/Backup and set a job schedule
2. Open the window Scheduled Tasks – Start/Control Panel/Scheduled Tasks and find the newly created scheduled job.
3. From the properties window of this job copy the highlighted text from the Run text field
4. Copy this text in a new batch file called ‘mybackup.bat’ (any name you like without quotes)
5. Take a note of the batch file location and enter the full path in the Run text field of step 3 ex: c:\documents\mybackup.bat
6. Close the properties window by clicking OK and enter an admin password if prompted
7. Add the sample script shown below in the batch file after the text entered in step 4
8. Edit the script text to reflect your email & path settings
Sample script
Copied text from step 3 goes here
@echo off
set Sender=”source email addess”
set Receiver=”your email address”
set Host=”IP address of source email server”
set Subject=”Backup name/title”
set logdir=”%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data”
REM ex – C:\Documents and Settings\administrator\ for %USERPROFILE%
set result=”%temp%\latestlog.txt”
pushd %logdir%
for /f “tokens=1 delims=” %%I in (‘dir /B /O-D’) do (
if “%%~xI”==”.log” (
type “%%~fI” > %result%
goto :end
)
)
:end
popd
c:\windows\system32\blat.exe %result% -f %Sender% -to %Receiver% -server %Host% -subject %Subject%
del /q /f “%result%”
The implementation steps of the script are as follows:
1. Create a backup job using Windows backup – Start/All Programs/Accessories/System Tools/Backup and set a job schedule
2. Open the window Scheduled Tasks – Start/Control Panel/Scheduled Tasks and find the newly created scheduled job.
3. From the properties window of this job copy the highlighted text from the Run text field
4. Copy this text in a new batch file called ‘mybackup.bat’ (any name you like without quotes)
5. Take a note of the batch file location and enter the full path in the Run text field of step 3 ex: c:\documents\mybackup.bat
6. Close the properties window by clicking OK and enter an admin password if prompted
7. Add the sample script shown below in the batch file after the text entered in step 4
8. Edit the script text to reflect your email & path settings
Sample script
Copied text from step 3 goes here
@echo off
set Sender=”source email addess”
set Receiver=”your email address”
set Host=”IP address of source email server”
set Subject=”Backup name/title”
set logdir=”%USERPROFILE%\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data”
REM ex – C:\Documents and Settings\administrator\ for %USERPROFILE%
set result=”%temp%\latestlog.txt”
pushd %logdir%
for /f “tokens=1 delims=” %%I in (‘dir /B /O-D’) do (
if “%%~xI”==”.log” (
type “%%~fI” > %result%
goto :end
)
)
:end
popd
c:\windows\system32\blat.exe %result% -f %Sender% -to %Receiver% -server %Host% -subject %Subject%
del /q /f “%result%”
Saturday, 22 October 2011
configure Catch All Mailbox on Exchange server
http://support.microsoft.com/kb/324021
This article describes how to create an event sink to capture all e-mail messages that are sent to a particular domain, and then direct them to a single mailbox.
Note The sample event sink described in this article redirects all e-mail messages that are sent to a domain. For information about how to create more complex event sinks, see the Exchange Software Development Kit (SDK).
Back to the top
Create the script files
Create the following five scripts, and then store them in a folder on the Exchange computer.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Catchall.cmd
The Catchall.cmd file calls the SMTPReg.vbs script and registers the Catchall event sink. To create this .cmd file, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /add 1 onarrival SMTPScriptingCatchAll CDO.SS_SMTPOnArrivalSink "mail from=*"
cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingCatchAll Sink ScriptName d:\mec\catchall\catchall.vbs
cscript smtpreg.vbs /delprop 1 onarrival SMTPScriptingCatchAll Source Rule
Note Modify the path to the Catchall.vbs file to reflect the folder location of the Catchall files.
Save the file as Catchall.cmd.
Enum.cmd
Run Enum.cmd to list event sinks that are registered on the server. To create this file, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /enum |more
Save the file as Enum.cmd.
Catchall.vbs
The Catchall.vbs script is used to create the Catchall account. Customize this file for your Exchange Server environment.
Type or paste the following code into a text editor, such as Notepad. Save this file as Catchall.vbs.
Edit the Catchall.vbs file to replace occurrences of @example.com with @yourdomain.com, where yourdomain.com is the domain from which you want to redirect the e-mail messages.
Replace all occurrences of bob@company.com with the SMTP address of the mailbox to which you want to redirect all e-mail messages for the domain that you specified in step 2.
Note The e-mail address to which you want to redirect all mail must be from a different domain than the domain from which you want to redirect the e-mail messages. For example, if the domain that you specify in step 2 is @company.com, the e-mail address that you specify in step 3 cannot be bob@company.com. If the domains are the same, the message will continuously loop and will eventually be returned to the sender as undeliverable.
If the recipient must have an e-mail address in the catchall domain (the domain from which you want to redirect the e-mail messages), such as bob@company.com, add an additional domain such as @company.local to the recipient policy for the user, and then add a SMTP address of bob@company.local to the user's e-mail addresses. The address of bob@company.local can then be used as the e-mail address to specify in step 3.
SMTPReg.vbs
Create a script to register the Catchall event sink. To do this, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
'WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
'INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
'OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
'PURPOSE
'------------------------------------------------------------------------------
'FILE DESCRIPTION: Script for registering for SMTP Protocol sinks.
'
'File Name: smtpreg.vbs
'
'
' Copyright (c) Microsoft Corporation 1993-1998. All rights reserved.
'------------------------------------------------------------------------------
Option Explicit
'
'
' the OnArrival event GUID
Const GUIDComCatOnArrival = "{ff3caa23-00b9-11d2-9dfb-00C04FA322BA}"
' the SMTP source type
Const GUIDSourceType = "{FB65C4DC-E468-11D1-AA67-00C04FA345F6}"
'
Const GUIDCat = "{871736c0-fd85-11d0-869a-00c04fd65616}"
Const GUIDSources = "{DBC71A31-1F4B-11d0-869D-80C04FD65616}"
' the SMTP service display name. This is used to key which service to
' edit
Const szService = "smtpsvc"
' the event manager object. This is used to communicate with the
' event binding database.
Dim EventManager
Set EventManager = WScript.CreateObject("Event.Manager")
'
' register a new sink with event manager
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name for this new sink
' szProgID - the progid to call for this event
' szRule - the rule to set for this event
'
public sub RegisterSink(iInstance, szEvent, szDisplayName, szProgID, szRule)
Dim SourceType
Dim szSourceDisplayName
Dim Source
Dim Binding
Dim GUIDComCat
Dim PrioVal
' figure out which event they are trying to register with and set
' the comcat for this event in GUIDComCat
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' enumerate through each of the registered instances for the SMTP source
' type and look for the display name that matches the instance display
' name
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' You have found the instance that you want. Now add a new binding
' with the right event GUID. by not specifying a GUID to the
' Add method you get server events to create a new ID for this
' event
set Binding = Source.GetBindingManager.Bindings(GUIDComCat).Add("")
' set the binding properties
Binding.DisplayName = szDisplayName
Binding.SinkClass = szProgID
' register a rule with the binding
Binding.SourceProperties.Add "Rule", szRule
' register a priority with the binding
PrioVal = GetNextPrio(Source, GUIDComCat)
If PrioVal < 0 then
WScript.Echo "assigning priority to default value (24575)"
Binding.SourceProperties.Add "Priority", 24575
else
WScript.Echo "assigning priority (" & PrioVal & " of 32767)"
Binding.SourceProperties.Add "Priority", PrioVal
end if
' save the binding
Binding.Save
WScript.Echo "registered " & szDisplayName
exit sub
end if
next
end sub
'
' iterate through the bindings in a source, find the binding
' with the lowest priority, and return the next priority value.
' If the next value exceeds the range, return -1.
'
public function GetNextPrio(oSource, GUIDComCat)
' it's possible that priority values will not be
' numbers, so you add error handling for this case
on error resume next
Dim Bindings
Dim Binding
Dim nLowestPrio
Dim nPrioVal
nLowestPrio = 0
set Bindings = oSource.GetBindingManager.Bindings(GUIDComCat)
' if the bindings collection is empty, then this is the first
' sink. It receives the highest priority (0).
if Bindings.Count = 0 then
GetNextPrio = 0
else
' get the lowest existing priority value
for each Binding in Bindings
nPrioVal = Binding.SourceProperties.Item("Priority")
if CInt(nPrioVal) > nLowestPrio then
if err.number = 13 then
err.clear
else
nLowestPrio = CInt(nPrioVal)
end if
end if
next
' assign priority values in increments of 10 so priorities
' can be shuffled later without the need to reorder all
' binding priorities. Valid priority values are 0 - 32767
if nLowestPrio + 10 > 32767 then
GetNextPrio = -1
else
GetNextPrio = nLowestPrio + 10
end if
end if
end function
'
' Search for a previously registered sink with the passed in name
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name of the event to check
' bCheckError - Any errors returned
public sub CheckSink(iInstance, szEvent, szDisplayName, bCheckError)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
bCheckError = FALSE
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' you have found the binding, now log an error
WScript.Echo "Binding with the name " & szDisplayName & " already exists"
exit sub
end if
next
end if
next
bCheckError = TRUE
end sub
'
' unregister a previously registered sink
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name of the event to remove
'
public sub UnregisterSink(iInstance, szEvent, szDisplayName)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' you have found the binding, now remove it
Bindings.Remove(Binding.ID)
WScript.Echo "removed " & szDisplayName & " " & Binding.ID
end if
next
end if
next
end sub
'
' add or remove a property from the source or sink propertybag for an event
'
' iInstance - the SMTP instance to edit
' szEvent - the event type (OnArrival)
' szDisplayName - the display name of the event
' szPropertyBag - the property bag to edit ("source" or "sink")
' szOperation - "add" or "remove"
' szPropertyName - the name to edit in the property bag
' szPropertyValue - the value to assign to the name (ignored for remove)
'
public sub EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, szOperation, szPropertyName, szPropertyValue)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
Dim PropertyBag
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' figure out which set of properties you want to modify
' based on the szPropertyBag parameter
select case LCase(szPropertyBag)
case "source"
set PropertyBag = Binding.SourceProperties
case "sink"
set PropertyBag = Binding.SinkProperties
case else
WScript.echo "invalid propertybag: " & szPropertyBag
exit sub
end select
' figure out what operation you want to perform
select case LCase(szOperation)
case "remove"
' they want to remove szPropertyName from the
' property bag
PropertyBag.Remove szPropertyName
WScript.echo "removed property " & szPropertyName
case "add"
' add szPropertyName to the property bag and
' set its value to szValue. if this value
' already exists then this will change the value
' it to szValue.
PropertyBag.Add szPropertyName, szPropertyValue
WScript.echo "set property " & szPropertyName & " to " & szPropertyValue
case else
WScript.echo "invalid operation: " & szOperation
exit sub
end select
' save the binding
Binding.Save
end if
next
end if
next
end sub
'
' this helper function takes an IEventSource object and a event category
' and dumps all of the bindings for this category under the source
'
' Source - the IEventSource object to display the bindings for
' GUIDComCat - the event category to display the bindings for
'
public sub DisplaySinksHelper(Source, GUIDComCat)
Dim Binding
Dim propval
' walk each of the registered bindings for this component category
for each Binding in Source.GetBindingManager.Bindings(GUIDComCat)
' display the binding properties
WScript.echo " Binding " & Binding.ID & " {"
WScript.echo " DisplayName = " & Binding.DisplayName
WScript.echo " SinkClass = " & Binding.SinkClass
if Binding.Enabled = True then
WScript.echo " Status = Enabled"
else
WScript.echo " Status = Disabled"
end if
' walk each of the source properties and display them
WScript.echo " SourceProperties {"
for each propval in Binding.SourceProperties
WScript.echo " " & propval & " = " & Binding.SourceProperties.Item(propval)
next
WScript.echo " }"
' walk each of the sink properties and display them
WScript.echo " SinkProperties {"
for each Propval in Binding.SinkProperties
WScript.echo " " & propval & " = " & Binding.SinkProperties.Item(Propval)
next
WScript.echo " }"
WScript.echo " }"
next
end sub
'
' dumps all of the information in the binding database related to SMTP
'
public sub DisplaySinks
Dim SourceType
Dim Source
' look for each of the sources registered for the SMTP source type
set SourceType = EventManager.SourceTypes(GUIDSourceType)
for each Source in SourceType.Sources
' display the source properties
WScript.echo "Source " & Source.ID & " {"
WScript.echo " DisplayName = " & Source.DisplayName
' display all of the sinks registered for the OnArrival event
WScript.echo " OnArrival Sinks {"
call DisplaySinksHelper(Source, GUIDComCatOnArrival)
WScript.echo " }"
next
end sub
'
' enable/disable a registered sink
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name for this new sink
'
public sub SetSinkEnabled(iInstance, szEvent, szDisplayName, szEnable)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " + szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService + " " + iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' You have found the binding, now enable/disable it
' You do not need "case else' because szEnable's value
' is set internally, not by users
select case LCase(szEnable)
case "true"
Binding.Enabled = True
Binding.Save
WScript.Echo "enabled " + szDisplayName + " " + Binding.ID
case "false"
Binding.Enabled = False
Binding.Save
WScript.Echo "disabled " + szDisplayName + " " + Binding.ID
end select
end if
next
end if
next
end sub
'
' display usage information for this script
'
public sub DisplayUsage
WScript.echo "usage: cscript smtpreg.vbs "
WScript.echo " commands:"
WScript.echo " /add "
WScript.echo " /remove "
WScript.echo " /setprop "
WScript.echo ""
WScript.echo " /delprop "
WScript.echo " /enable "
WScript.echo " /disable "
WScript.echo " /enum"
WScript.echo " arguments:"
WScript.echo " is the SMTP instance to work against"
WScript.echo " can be OnArrival"
WScript.echo " is the display name of the event to edit"
WScript.echo " is the sink class for the event"
WScript.echo " is the rule to use for the event"
WScript.echo " can be Source or Sink"
WScript.echo " is the name of the property to edit"
WScript.echo " is the value to assign to the property"
end sub
Dim iInstance
Dim szEvent
Dim szDisplayName
Dim szSinkClass
Dim szRule
Dim szPropertyBag
Dim szPropertyName
Dim szPropertyValue
dim bCheck
'
' this is the main body of our script. it reads the command line parameters
' specified and then calls the appropriate function to perform the operation
'
if WScript.Arguments.Count = 0 then
call DisplayUsage
else
Select Case LCase(WScript.Arguments(0))
Case "/add"
if not WScript.Arguments.Count = 6 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szSinkClass = WScript.Arguments(4)
szRule = WScript.Arguments(5)
call CheckSink(iInstance, szEvent, szDisplayName, bCheck)
if bCheck = TRUE then
call RegisterSink(iInstance, szEvent, szDisplayName, szSinkClass, szRule)
End if
end if
Case "/remove"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call UnregisterSink(iInstance, szEvent, szDisplayName)
end if
Case "/setprop"
if not WScript.Arguments.Count = 7 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szPropertyBag = WScript.Arguments(4)
szPropertyName = WScript.Arguments(5)
szPropertyValue = WScript.Arguments(6)
call EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, "add", szPropertyName, szPropertyValue)
end if
Case "/delprop"
if not WScript.Arguments.Count = 6 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szPropertyBag = WScript.Arguments(4)
szPropertyName = WScript.Arguments(5)
call EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, "remove", szPropertyName, "")
end if
Case "/enable"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call SetSinkEnabled(iInstance, szEvent, szDisplayName, "True")
end if
Case "/disable"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call SetSinkEnabled(iInstance, szEvent, szDisplayName, "False")
end if
Case "/enum"
if not WScript.Arguments.Count = 1 then
call DisplayUsage
else
call DisplaySinks
end if
Case Else
call DisplayUsage
End Select
end if
Save the file as Smtpreg.vbs.
Removecatchall.cmd
Create a .cmd file to remove (uninstall) the Catchall event sink if you think that you may want to remove it later. To do this, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /remove 1 onarrival SMTPScriptingCatchAll
Save this file as Removecatchall.cmd.
Note If you want to remove the Catchall event sink, you can do so by running Removecatchall.cmd from a command prompt.
Back to the top
Register the catchall event sink
Verify that you have created a valid e-mail account with which to collect the redirected e-mail messages.
Run the Catchall.cmd from the directory that contains the .vbs files that you created.
Restart the SMTP service in the Exchange System Manager.
Test the event sink by sending an e-mail message to an e-mail address in the catchall domain that you specified in step 2 of the "Catchall.vbs" section of this article. The message is delivered to the recipient mailbox with the address that you specified in step 3 of that same article section.
This article describes how to create an event sink to capture all e-mail messages that are sent to a particular domain, and then direct them to a single mailbox.
Note The sample event sink described in this article redirects all e-mail messages that are sent to a domain. For information about how to create more complex event sinks, see the Exchange Software Development Kit (SDK).
Back to the top
Create the script files
Create the following five scripts, and then store them in a folder on the Exchange computer.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Catchall.cmd
The Catchall.cmd file calls the SMTPReg.vbs script and registers the Catchall event sink. To create this .cmd file, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /add 1 onarrival SMTPScriptingCatchAll CDO.SS_SMTPOnArrivalSink "mail from=*"
cscript smtpreg.vbs /setprop 1 onarrival SMTPScriptingCatchAll Sink ScriptName d:\mec\catchall\catchall.vbs
cscript smtpreg.vbs /delprop 1 onarrival SMTPScriptingCatchAll Source Rule
Note Modify the path to the Catchall.vbs file to reflect the folder location of the Catchall files.
Save the file as Catchall.cmd.
Enum.cmd
Run Enum.cmd to list event sinks that are registered on the server. To create this file, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /enum |more
Save the file as Enum.cmd.
Catchall.vbs
The Catchall.vbs script is used to create the Catchall account. Customize this file for your Exchange Server environment.
Type or paste the following code into a text editor, such as Notepad. Save this file as Catchall.vbs.
Edit the Catchall.vbs file to replace occurrences of @example.com with @yourdomain.com, where yourdomain.com is the domain from which you want to redirect the e-mail messages.
Replace all occurrences of bob@company.com with the SMTP address of the mailbox to which you want to redirect all e-mail messages for the domain that you specified in step 2.
Note The e-mail address to which you want to redirect all mail must be from a different domain than the domain from which you want to redirect the e-mail messages. For example, if the domain that you specify in step 2 is @company.com, the e-mail address that you specify in step 3 cannot be bob@company.com. If the domains are the same, the message will continuously loop and will eventually be returned to the sender as undeliverable.
If the recipient must have an e-mail address in the catchall domain (the domain from which you want to redirect the e-mail messages), such as bob@company.com, add an additional domain such as @company.local to the recipient policy for the user, and then add a SMTP address of bob@company.local to the user's e-mail addresses. The address of bob@company.local can then be used as the e-mail address to specify in step 3.
SMTPReg.vbs
Create a script to register the Catchall event sink. To do this, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
'THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT
'WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
'INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
'OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
'PURPOSE
'------------------------------------------------------------------------------
'FILE DESCRIPTION: Script for registering for SMTP Protocol sinks.
'
'File Name: smtpreg.vbs
'
'
' Copyright (c) Microsoft Corporation 1993-1998. All rights reserved.
'------------------------------------------------------------------------------
Option Explicit
'
'
' the OnArrival event GUID
Const GUIDComCatOnArrival = "{ff3caa23-00b9-11d2-9dfb-00C04FA322BA}"
' the SMTP source type
Const GUIDSourceType = "{FB65C4DC-E468-11D1-AA67-00C04FA345F6}"
'
Const GUIDCat = "{871736c0-fd85-11d0-869a-00c04fd65616}"
Const GUIDSources = "{DBC71A31-1F4B-11d0-869D-80C04FD65616}"
' the SMTP service display name. This is used to key which service to
' edit
Const szService = "smtpsvc"
' the event manager object. This is used to communicate with the
' event binding database.
Dim EventManager
Set EventManager = WScript.CreateObject("Event.Manager")
'
' register a new sink with event manager
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name for this new sink
' szProgID - the progid to call for this event
' szRule - the rule to set for this event
'
public sub RegisterSink(iInstance, szEvent, szDisplayName, szProgID, szRule)
Dim SourceType
Dim szSourceDisplayName
Dim Source
Dim Binding
Dim GUIDComCat
Dim PrioVal
' figure out which event they are trying to register with and set
' the comcat for this event in GUIDComCat
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' enumerate through each of the registered instances for the SMTP source
' type and look for the display name that matches the instance display
' name
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' You have found the instance that you want. Now add a new binding
' with the right event GUID. by not specifying a GUID to the
' Add method you get server events to create a new ID for this
' event
set Binding = Source.GetBindingManager.Bindings(GUIDComCat).Add("")
' set the binding properties
Binding.DisplayName = szDisplayName
Binding.SinkClass = szProgID
' register a rule with the binding
Binding.SourceProperties.Add "Rule", szRule
' register a priority with the binding
PrioVal = GetNextPrio(Source, GUIDComCat)
If PrioVal < 0 then
WScript.Echo "assigning priority to default value (24575)"
Binding.SourceProperties.Add "Priority", 24575
else
WScript.Echo "assigning priority (" & PrioVal & " of 32767)"
Binding.SourceProperties.Add "Priority", PrioVal
end if
' save the binding
Binding.Save
WScript.Echo "registered " & szDisplayName
exit sub
end if
next
end sub
'
' iterate through the bindings in a source, find the binding
' with the lowest priority, and return the next priority value.
' If the next value exceeds the range, return -1.
'
public function GetNextPrio(oSource, GUIDComCat)
' it's possible that priority values will not be
' numbers, so you add error handling for this case
on error resume next
Dim Bindings
Dim Binding
Dim nLowestPrio
Dim nPrioVal
nLowestPrio = 0
set Bindings = oSource.GetBindingManager.Bindings(GUIDComCat)
' if the bindings collection is empty, then this is the first
' sink. It receives the highest priority (0).
if Bindings.Count = 0 then
GetNextPrio = 0
else
' get the lowest existing priority value
for each Binding in Bindings
nPrioVal = Binding.SourceProperties.Item("Priority")
if CInt(nPrioVal) > nLowestPrio then
if err.number = 13 then
err.clear
else
nLowestPrio = CInt(nPrioVal)
end if
end if
next
' assign priority values in increments of 10 so priorities
' can be shuffled later without the need to reorder all
' binding priorities. Valid priority values are 0 - 32767
if nLowestPrio + 10 > 32767 then
GetNextPrio = -1
else
GetNextPrio = nLowestPrio + 10
end if
end if
end function
'
' Search for a previously registered sink with the passed in name
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name of the event to check
' bCheckError - Any errors returned
public sub CheckSink(iInstance, szEvent, szDisplayName, bCheckError)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
bCheckError = FALSE
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' you have found the binding, now log an error
WScript.Echo "Binding with the name " & szDisplayName & " already exists"
exit sub
end if
next
end if
next
bCheckError = TRUE
end sub
'
' unregister a previously registered sink
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name of the event to remove
'
public sub UnregisterSink(iInstance, szEvent, szDisplayName)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' you have found the binding, now remove it
Bindings.Remove(Binding.ID)
WScript.Echo "removed " & szDisplayName & " " & Binding.ID
end if
next
end if
next
end sub
'
' add or remove a property from the source or sink propertybag for an event
'
' iInstance - the SMTP instance to edit
' szEvent - the event type (OnArrival)
' szDisplayName - the display name of the event
' szPropertyBag - the property bag to edit ("source" or "sink")
' szOperation - "add" or "remove"
' szPropertyName - the name to edit in the property bag
' szPropertyValue - the value to assign to the name (ignored for remove)
'
public sub EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, szOperation, szPropertyName, szPropertyValue)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
Dim PropertyBag
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " & szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService & " " & iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' figure out which set of properties you want to modify
' based on the szPropertyBag parameter
select case LCase(szPropertyBag)
case "source"
set PropertyBag = Binding.SourceProperties
case "sink"
set PropertyBag = Binding.SinkProperties
case else
WScript.echo "invalid propertybag: " & szPropertyBag
exit sub
end select
' figure out what operation you want to perform
select case LCase(szOperation)
case "remove"
' they want to remove szPropertyName from the
' property bag
PropertyBag.Remove szPropertyName
WScript.echo "removed property " & szPropertyName
case "add"
' add szPropertyName to the property bag and
' set its value to szValue. if this value
' already exists then this will change the value
' it to szValue.
PropertyBag.Add szPropertyName, szPropertyValue
WScript.echo "set property " & szPropertyName & " to " & szPropertyValue
case else
WScript.echo "invalid operation: " & szOperation
exit sub
end select
' save the binding
Binding.Save
end if
next
end if
next
end sub
'
' this helper function takes an IEventSource object and a event category
' and dumps all of the bindings for this category under the source
'
' Source - the IEventSource object to display the bindings for
' GUIDComCat - the event category to display the bindings for
'
public sub DisplaySinksHelper(Source, GUIDComCat)
Dim Binding
Dim propval
' walk each of the registered bindings for this component category
for each Binding in Source.GetBindingManager.Bindings(GUIDComCat)
' display the binding properties
WScript.echo " Binding " & Binding.ID & " {"
WScript.echo " DisplayName = " & Binding.DisplayName
WScript.echo " SinkClass = " & Binding.SinkClass
if Binding.Enabled = True then
WScript.echo " Status = Enabled"
else
WScript.echo " Status = Disabled"
end if
' walk each of the source properties and display them
WScript.echo " SourceProperties {"
for each propval in Binding.SourceProperties
WScript.echo " " & propval & " = " & Binding.SourceProperties.Item(propval)
next
WScript.echo " }"
' walk each of the sink properties and display them
WScript.echo " SinkProperties {"
for each Propval in Binding.SinkProperties
WScript.echo " " & propval & " = " & Binding.SinkProperties.Item(Propval)
next
WScript.echo " }"
WScript.echo " }"
next
end sub
'
' dumps all of the information in the binding database related to SMTP
'
public sub DisplaySinks
Dim SourceType
Dim Source
' look for each of the sources registered for the SMTP source type
set SourceType = EventManager.SourceTypes(GUIDSourceType)
for each Source in SourceType.Sources
' display the source properties
WScript.echo "Source " & Source.ID & " {"
WScript.echo " DisplayName = " & Source.DisplayName
' display all of the sinks registered for the OnArrival event
WScript.echo " OnArrival Sinks {"
call DisplaySinksHelper(Source, GUIDComCatOnArrival)
WScript.echo " }"
next
end sub
'
' enable/disable a registered sink
'
' iInstance - the instance to work against
' szEvent - OnArrival
' szDisplayName - the display name for this new sink
'
public sub SetSinkEnabled(iInstance, szEvent, szDisplayName, szEnable)
Dim SourceType
Dim GUIDComCat
Dim szSourceDisplayName
Dim Source
Dim Bindings
Dim Binding
select case LCase(szEvent)
case "onarrival"
GUIDComCat = GUIDComCatOnArrival
case else
WScript.echo "invalid event: " + szEvent
exit sub
end select
' find the source for this instance
set SourceType = EventManager.SourceTypes(GUIDSourceType)
szSourceDisplayName = szService + " " + iInstance
for each Source in SourceType.Sources
if Source.DisplayName = szSourceDisplayName then
' find the binding by display name. to do this, enumerate
' all of the bindings and try to match on the display name
set Bindings = Source.GetBindingManager.Bindings(GUIDComCat)
for each Binding in Bindings
if Binding.DisplayName = szDisplayName then
' You have found the binding, now enable/disable it
' You do not need "case else' because szEnable's value
' is set internally, not by users
select case LCase(szEnable)
case "true"
Binding.Enabled = True
Binding.Save
WScript.Echo "enabled " + szDisplayName + " " + Binding.ID
case "false"
Binding.Enabled = False
Binding.Save
WScript.Echo "disabled " + szDisplayName + " " + Binding.ID
end select
end if
next
end if
next
end sub
'
' display usage information for this script
'
public sub DisplayUsage
WScript.echo "usage: cscript smtpreg.vbs
WScript.echo " commands:"
WScript.echo " /add
WScript.echo " /remove
WScript.echo " /setprop
WScript.echo "
WScript.echo " /delprop
WScript.echo " /enable
WScript.echo " /disable
WScript.echo " /enum"
WScript.echo " arguments:"
WScript.echo "
WScript.echo "
WScript.echo "
WScript.echo "
WScript.echo "
WScript.echo "
WScript.echo "
WScript.echo "
end sub
Dim iInstance
Dim szEvent
Dim szDisplayName
Dim szSinkClass
Dim szRule
Dim szPropertyBag
Dim szPropertyName
Dim szPropertyValue
dim bCheck
'
' this is the main body of our script. it reads the command line parameters
' specified and then calls the appropriate function to perform the operation
'
if WScript.Arguments.Count = 0 then
call DisplayUsage
else
Select Case LCase(WScript.Arguments(0))
Case "/add"
if not WScript.Arguments.Count = 6 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szSinkClass = WScript.Arguments(4)
szRule = WScript.Arguments(5)
call CheckSink(iInstance, szEvent, szDisplayName, bCheck)
if bCheck = TRUE then
call RegisterSink(iInstance, szEvent, szDisplayName, szSinkClass, szRule)
End if
end if
Case "/remove"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call UnregisterSink(iInstance, szEvent, szDisplayName)
end if
Case "/setprop"
if not WScript.Arguments.Count = 7 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szPropertyBag = WScript.Arguments(4)
szPropertyName = WScript.Arguments(5)
szPropertyValue = WScript.Arguments(6)
call EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, "add", szPropertyName, szPropertyValue)
end if
Case "/delprop"
if not WScript.Arguments.Count = 6 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
szPropertyBag = WScript.Arguments(4)
szPropertyName = WScript.Arguments(5)
call EditProperty(iInstance, szEvent, szDisplayName, szPropertyBag, "remove", szPropertyName, "")
end if
Case "/enable"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call SetSinkEnabled(iInstance, szEvent, szDisplayName, "True")
end if
Case "/disable"
if not WScript.Arguments.Count = 4 then
call DisplayUsage
else
iInstance = WScript.Arguments(1)
szEvent = WScript.Arguments(2)
szDisplayName = WScript.Arguments(3)
call SetSinkEnabled(iInstance, szEvent, szDisplayName, "False")
end if
Case "/enum"
if not WScript.Arguments.Count = 1 then
call DisplayUsage
else
call DisplaySinks
end if
Case Else
call DisplayUsage
End Select
end if
Save the file as Smtpreg.vbs.
Removecatchall.cmd
Create a .cmd file to remove (uninstall) the Catchall event sink if you think that you may want to remove it later. To do this, follow these steps:
Type or paste the following code into a text editor, such as Notepad:
cscript smtpreg.vbs /remove 1 onarrival SMTPScriptingCatchAll
Save this file as Removecatchall.cmd.
Note If you want to remove the Catchall event sink, you can do so by running Removecatchall.cmd from a command prompt.
Back to the top
Register the catchall event sink
Verify that you have created a valid e-mail account with which to collect the redirected e-mail messages.
Run the Catchall.cmd from the directory that contains the .vbs files that you created.
Restart the SMTP service in the Exchange System Manager.
Test the event sink by sending an e-mail message to an e-mail address in the catchall domain that you specified in step 2 of the "Catchall.vbs" section of this article. The message is delivered to the recipient mailbox with the address that you specified in step 3 of that same article section.
Subscribe to:
Posts (Atom)
ISM Cyber Security Terms
ISM Cyber Security Terms
-
--> Phase 3 :- Installation of Windows Exchange server standard 2007 SP1 & Move Mailbox, Installtion/Transfer of Commercial Certi...
-
If you have PABX server like Asterisk / Free PBX / Elastix and want to feature to listen / whisper / barge to other calls. ChanSpy can gi...