I have no issues sending an HTML email using Send-MailMessage, but is there any way that I can insert the value of a variable?
CSV:
email,samaccountname,newSAM,
[email protected],john.doe,jdoe,
Command:
$html = (Get-Content .\email.html)
Import-Csv .\my-file.csv |
ForEach-Object {
Send-MailMessage -SmtpServer 10.0.0.1 -Subject "Subject Here" -From [email protected] -To $_.email -Priority: High -BodyAsHtml "$html"
}
HTML Body:
<html>
<head>
<title>HTML Generator Sample Page</title>
</head>
<body>
<p>
<span style="font-family:times new roman,times,serif;"><span style="font-size: 12px;"><strong>Old username: $_.samaccountname </strong></span></span></p>
<p>
<span style="font-family:times new roman,times,serif;"><span style="font-size: 12px;"><strong>New username: $_.newSAM </strong></span></span></p>
</body>
</html>
The email body shows $_.newSAM instead of the value imported from the .CSV file. Thanks in advance for any assistance!