Tag Archives: Email

New Free Tool: Citrix Director Notification Service

DirectorNotificationCitrix Director for XenApp and XenDesktop can be a great utility for information about your Application / Desktop virtualisation environment. In Director you can find a wealth of information about the provisioned assets, the Controller, Licensing and Hypervisor status and the current running resources.

One area it’s always lacked is real time alerting. In order to really know what’s going on in your environment you need to be logged into director and watching. This is less than ideal and few monitoring vendors have endeavored to actually pull this data into their own solutions.

With the help of Rachel Berry, Prateek Kansal and Sridhar Mullapudi from Citrix. I set about diving into the logic and monitoring options within the FMA architecture. Citrix did a great job here and most if not all of it was readily available in PowerShell and oData. So, with the help of Citrix and a little bit of hard work, I’m very pleased to announce my latest free tool!

Continue reading

Sending An email via a script:

Recently i found myself in need of the ability to email a status script to my team. Not only this, but it would also need to attach an file. This script would run when a service stopped, start the service with a batch file doing a simple “net start ‘service'”, querying the service with psservice then call a VBS file to email the results of the net start command. This gave us visability of crappy software services stopping and the attempted automated restart.

I came across this script on our corporate network, cant give the credit as dont know where its due, but its excellent for a free script. More info after the jump, its quite a large script.

_____________________________________________________________________________________

dtmDate = Date

strMonth = Month(Date)
strDay = Day(Date)
strYear = Right(Year(Date),2)

bFlag = CDOSYS_Send_Email(“<server>”,””,””,”<Recipient1@email.com;Recipient2@email.com>”,””,””,”<From address>”,”<Subject>””<Message Body>”,”<attachment>”)

Function CDOSYS_Send_Email(sSmtpServer,sUsername,sPassword,sTo,sCC,sBCC,sFrom,sSubject,sBody,sAttach)
On Error Resume Next
‘These weird constants do NOT cause any communications with schemas.microsoft.com. They are just naming conventions.
Const cdoSendUsingMethod = “http://schemas.microsoft.com/cdo/configuration/sendusing”
Const cdoSMTPServer = “http://schemas.microsoft.com/cdo/configuration/smtpserver”
Const cdoSMTPServerPort = “http://schemas.microsoft.com/cdo/configuration/smtpserverport”
Const cdoSMTPConnectionTimeout = “http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”
Const cdoSMTPAuthenticate = “http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”
Const cdoSendUserName = “http://schemas.microsoft.com/cdo/configuration/sendusername”
Const cdoSendPassword = “http://schemas.microsoft.com/cdo/configuration/sendpassword”
Const cdoSendUsingPickup = 1 ‘Use the local IIS-SMTP service for delivery.
Const cdoSendUsingPort = 2 ‘Use a remote SMTP server for delivery.

Set oMessage = WScript.CreateObject(“CDO.Message”)
Set oConfiguration = WScript.CreateObject(“CDO.Configuration”)

Set cFields = oConfiguration.Fields
cFields.Item(cdoSendUsingMethod) = cdoSendUsingPort ‘cdoSendUsingPort = Send to remote SMTP server (2), cdoSendUsingPickup = Send using local SMTP service (1).
cFields.Item(cdoSMTPServer) = sSmtpServer ‘IP address or DNS name of the remote SMTP server.
cFields.Item(cdoSMTPServerPort) = 25
cFields.Item(cdoSMTPConnectionTimeout) = 30 ‘Timeout in seconds for connection.

If LCase(sUsername) = “ntlm” Then
cFields.Item(cdoSMTPAuthenticate) = 2 ‘2 = NTLM authentication. NTLM uses the credentials of the WSH process itself.
ElseIf sUsername <> “” Then
cFields.Item(cdoSMTPAuthenticate) = 1 ‘1 = Basic authentication.
cFields.Item(cdoSendUserName) = sUsername ‘Username for Basic authentication, ignored for anonymous or NTLM authentication.
cFields.Item(cdoSendPassword) = sPassword ‘Password for Basic authentication, ignored for anonymous or NTLM authentication.
Else
cFields.Item(cdoSMTPAuthenticate) = 0 ‘0 = Anonymous authentication.
End If

cFields.Update ‘Save data so far.
Set oMessage.Configuration = oConfiguration

oMessage.To = sTo
oMessage.CC = sCC
oMessage.BCC = sBCC
oMessage.From = sFrom
oMessage.Subject = sSubject
oMessage.TextBody = sBody

If sAttach <> “” Then
aFiles = Split(sAttach,”;”)
For Each sFile In aFiles
oMessage.AddAttachment sFile
Next
End If

oMessage.Send

If Err.Number = 0 Then
CDOSYS_Send_Email = True
Else
CDOSYS_Send_Email = False
End If

Set oMessage = Nothing
Set oFields = Nothing
Set oConfiguration = Nothing
End Function

‘END OF SCRIPT *********************************************************************

______________________________________________________________________________________

The above variables seem to translate to these:

Arguments: sSmtpServer = IP address or FQDN of out-going SMTP server.
‘ sUsername = (May be blank.) Username for Basic authentication; set blank for Anonymous; set ntlm for NTLM.
‘ sPassword = (May be blank.) Password for Basic authentication; ignored for Anonymous and NTLM.
‘ sTo = Recipient. Semicolon-delimited for multiple addresses.
‘ sCC = (May be blank.) CC recipient. Semicolon-delimited for multiple addresses.
‘ sBCC = (May be blank.) Blind CC recipient. Semicolon-delimited for multiple addresses.
‘ sFrom = Single e-mail address for sender.
‘ sSubject = (May be blank.) Subject line.
‘ sBody = (May be blank.) Body of message.
‘ sAttach = (May be blank.) Full path to local file to attach. Semicolon-delimited for multiple addresses.

if you are having difficulty with sending the email, ensure the server/desktop you run this script from can telnet to the exchange/smtp server on port 25. to test this use:

telnet <smtp address> 25

HELO

Below is a working excerpt of my script:

CDOSYS_Send_Email(“172.26.11.76″,””,””,”Andrew.Morgan@o2.com”,”SpaceChecks for DailyChecklist”,”E:NT InfrastructureDaily ChecksDublinSpaceResults” & strMonth & “-” & strDay & “-” & strYear & “.xls”)

Happy coding =)