I have the following postcommit hook that executes when a commit is done:
PostCommit.bat
@ECHO OFF
set local
set REPOS=%1
set REV=%2
set TXN_NAME=%3
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%emailer.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' 'REPOS' 'REV' TXN_NAME";
I'm trying to send the repository link, Revision # and transaction via e-mail using the below powershell script.
emailer.ps1
function mailer($Repos,$Rev,$TXN_NAME)
{
$smtp = new-object Net.Mail.SmtpClient("webmail.companyname.com")
$objMailMessage = New-Object System.Net.Mail.MailMessage
$objMailMessage.From = "Automation@companyname.com"
$i = 0
Get-Content "X:\Department\Con\Hyd\Technical\TestPool\recepients.txt" | foreach {
$emailid = $_.split(";")
$emailid | foreach{
$objMailMessage.To.Add($emailid[$i])
$i++
}
}
$objMailMessage.Subject = "A commit operation has been performed! "
$objMailMessage.Body = "A commit operation has been performed at repository "+$Repos+" and the latest revision is "+$Rev
$smtp.send($objMailMessage)
}
Once I commit my changes, I don't see any error messages nor receive any e-mails. I guess the problem is while calling the powershell script via commandline. Also it would be great if anybody could suggest how to add the author's name in the mail.
Thanks in advance.