Service Catalogue send automated mail via PowerShell scripting

Service Catalogue send automated mail via PowerShell scripting

Hello,

I Create a PowerShell script than allows to send automatically mail to my requester with an attachment. 

My problem is that in "to"section it cannot take automatically requester's mail address.
This is the script:



param (
    $json = "none"
    
 )

$jsondata = Get-Content $json -Encoding UTF8   #Encode if necessary


$obj = ConvertFrom-Json $jsondata


#Add Request fields values as needed
$requester = $obj.request.REQUESTER
$subject = $obj.request.SUBJECT
$priority = $obj.request.PRIORITY
$ticket = $obj.request.WORKORDERID
$subcategory = $obj.request.SUBCATEGORY
$createdate = ([datetime]'1/1/1970').AddMilliseconds($obj.request.createdtime).ToString("dd/MM/yyyy - hh:mm") #Choose your timestamp format
$technician = $obj.request.TECHNICIAN
$file = "C:\ManageEngine\ServiceDesk\integration\custom_scripts\something .pdf"

#Insert smtp/smtps informations
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
$SMTPServer = "smtp.mydomain.com" # check if smtp or smtps
$SMTPPort = "25" #check your domain smtp port [25, 465 or 587]
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$smtp.EnableSSL = $true #check if it's necessary
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);

#Email message body [HTML]
$body = @"
<p>Dear $requester,</p>



<p>The TICKET ##$ticket## was opened. </p>

<p><font color=red>Please Read Carefully "something" </b></font></p><br>


<p>Ticket Details:</p>

<p>Subcategory: $subcategory <br>
Created Date: $createdate <br>
Technician: $technician</p>



"@


# Set sender, receiver, Subject, Cc and Bcc
$msg.From = "This is a test < test@mycompany.com>"
$msg.To.Add(" requester@mycompany.com")
#$msg.To.Add("...") # to second "To"
#$msg.cc.Add("...") #To Carbon Copy
#$msg.bcc.Add("...") #To Blind Carbon Copy
$msg.Subject = "Some subject or $subject"
$msg.Body = $body
$msg.IsBodyHTML = $true
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()


Please can somebody help me?

Best Regards,
Vangelis

                  New to ADSelfService Plus?