![]() |
|
|
| Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site | ||
|
|
IM Announcements to all user with a Exchange mailbox using an On_Arrival SMTP event sink Introduction
Download
script Comments Caveats SMTP OnArrival Event Installation cscript smtpreg.vbs /add 1 onarrival IMannouce CDO.SS_SMTPOnArrivalSink "mail to=imannouce@yourdomain.com" You then need to associate the smtpevt.vbs script to this event sink you have created using cscript smtpreg.vbs /setprop 1 onarrival IMannouce Sink ScriptName c:\smtpevt\smtpevt.vbs Once this has been done you need to stop and start the SMTP service and your event sink will now be active. If you wish to delete this event sink latter type cscript smtpreg.vbs /remove 1 onarrival IMannouce
Script Smtpevt.VBS (Event Sink Script) <SCRIPT LANGUAGE="VBScript"> Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus )
Dim Stm
Dim WshShell
Stm = Msg.Subject
set WshShell = CreateObject("WScript.Shell")
strrun = WshShell.run ("c:\smtpevt\sndmsg.vbs " & stm)
set WshShell = nothing
End Sub
</SCRIPT>
As you can see this code is dead easy it starts the other script and then goes back to what it was doing (it doesn't wait around to see if the other script was successfully or not). Note when you are writing any event sink scripts you must enclose you scripts in the <SCRIPT LANGUAGE="VBScript"></script> tags or your scripts wont work. Script Sndmsg.vbs The next piece of code is slightly more complicated it uses as the base the code I described in the "Sending and Instant Message's Programmatically article" for more information on customising the IM part of this script see this article. Lets have a look at this script Set objArgs = WScript.Arguments The front-end of this code accepts the subject line passed from the smtpevt.vbs script as a bunch of script arguments and loads them into one string for the message. The next bit of code sets up the Active directory connection (Hint you need to customise this bit here with your own AD and OU names). sub sendmsg()
strMsgHeader = "Mime-Version: 1.0" & vbCrLf & "Content-Type: text/plain; charset=UTF-8" & vbCrLf & vbCrLf
msgType = IM_MSG_TYPE_NO_RESULT
Set oIMApp = CreateObject("MSExchangeIM.MSIMHost")
Set oIMServ = oIMApp.CreateContext("Default", 0)
strtest = Array("newb1@exbend","newb1","pass","ad1")
oIMServ.logon strtest
do until iState = 2
oIMServ.GetLocalState iState, strState, strDescr
if loopexit = 1000 then
exit sub
end if
loopexit = loopexit + 1
loop
For Each oUser in OU
if oUser.Class = "user" then
if oUser.msExchIMAddress <> "" then
set oIMsession = oIMServ.CreateIMSession(oUser.msExchIMAddress)
oIMsession.Sendtext strMsgHeader, message, msgtype
On Error resume Next
End If
End If
Next
Set OU = Nothing
OIMServ.logoff()
set oIMApp = nothing
end sub
The body of the code opens up a connection to Active directory and searches each user object in the nominated OU for an Instant messaging user address. If one is found it tries to establish a session with this user and send them the message. If the user is not online an error will be generated and be caught by the "On error resume next" line and processing will continue. Security Improvements
|
Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.
Copyright Stephen Bryant 2008