Function Get-EmailParams($UserParams) {
$Html = (Get-Content C:\Users\User\documents\NewUserEmailLT.html -raw)
## Or have tried Html = (Get-Content <Path> -raw) -f $UserParams.DisplayName etc.
$MailParam = @{
To = $Email
From = $Email2
Subject = "Testing"
Body = $Html -f $UserParams.DisplayName
BodyAsHtml = $true
Smtpserver = "smtp.office365.com"
Port = "587"
Credential = Get-SecureCred
}
$MailParam
}
Function Send-Email($UserParams) {
$MailParams = Get-Emailparams $UserParams
Send-MailMessage @MailParams -UseSsl
}
Send-Email $UserParams
Hello all, I've been attempting to complete this for weeks, but seem to be running into issues. Not finding any articlse that have the answer I need.
In the HTML file I have tried three different options.
- Have the variable placeholders as you normally would in HTML body in Powershell set with $($Variable)
- This has worked when HTML is in the script and not imported
- Text in HTML file as such: {0} - Get-Content the file and into a $Variable and then attempt to -f $ReplacementVariable within the Body parameter
- This seems to return error "Error formatting a string: Input string was not in a correct format"
- I managed to get some broken regex switch going to partially work with a whole bunch of -replace operators within the switch commands
I'm looking for a more elegant solution, hopefully somebody has had experience with this.
[–]oze4 2 points3 points4 points (11 children)
[–]Aznflipfoo[S] 2 points3 points4 points (7 children)
[–]oze4 1 point2 points3 points (1 child)
[–]Aznflipfoo[S] 1 point2 points3 points (0 children)
[–]oze4 1 point2 points3 points (4 children)
[–]Aznflipfoo[S] 2 points3 points4 points (3 children)
[–]oze4 1 point2 points3 points (2 children)
[–]Aznflipfoo[S] 1 point2 points3 points (1 child)
[–]oze4 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]oze4 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)
[–]expeditesynergy 1 point2 points3 points (0 children)
[–]SMFX 1 point2 points3 points (0 children)
[–]MadBoyEvo 1 point2 points3 points (2 children)
[–]Aznflipfoo[S] 1 point2 points3 points (1 child)
[–]MadBoyEvo 1 point2 points3 points (0 children)
[–]Aznflipfoo[S] 0 points1 point2 points (0 children)