Powershell EMail: How to add new line in email Body?

(From my comment)

The PowerShell newline indicator is `n (backtick-n), so:

$Body = "Server Name:  $server, <NEED NEW LINE> Drive: C

becomes:

$Body = "Server Name:  $server, `n Drive: C

I'm not sure how these other users were able to make the `n create a new line but I never could get it to work...

Instead I ended up doing the following...

  • Using the -BodyAsHtml switch
  • Using the <br /> (break) html tag

For example...

powershell -ExecutionPolicy ByPass -Command Send-MailMessage -BodyAsHtml -SmtpServer 'myemail.server.com' -To 'Mr To <[email protected]>' -From 'Mr From <[email protected]>' -Subject 'Reports From Daily SQL Backup Jobs' -Body 'There was an issue backing up the databases and sending them to the virtual drive.<br />Test Line 2.<br />Test Line 3.-more on line 3<br />Test Line 4.<br />EOF<br />'"

technically it needs to be

$body = "first line" + "`n" + "second line"

otherwise the the first line is created with a trailing and the second line with a leading space.