I am new to PowerShell and I have a file.html which I need to insert into Email-message. I am able to insert the html file into email body. But I want to insert some content in the beginning of the email regarding the context. I can get the html content into a parameter with below command, but I need to insert some text in the body, before sending the Email message. Note that the parameter already has all tags with data. $body = Get-Content -Path C:\file.html -Raw
Asked
Active
Viewed 926 times
0
-
HTML is plain text, so you're looking for something like this: https://stackoverflow.com/questions/1875617/insert-content-into-text-file-in-powershell – Lee Exothermix Oct 22 '20 at 19:49
2 Answers
0
The Send-MailMessage
has an -attachments
parameter, and also an -body parameter, which you can use. If you want to have additional text you can add your text
send-MailMessage -body "(Your text here) $($body)" (Your remaining parameters)

Shaqil Ismail
- 1,794
- 1
- 4
- 5
0
If as you say the HTML body has all tags, this could be as simple as:
$textToInsert = 'This describes the body below'
$body = Get-Content -Path C:\file.html -Raw
$parts = $body -split '<body>', 2
$body = '{0}<body><p>{1}</p>{2}' -f $parts[0], $textToInsert, $parts[1]

Theo
- 57,719
- 8
- 24
- 41