• 0

Powershell - send-mail command construct


Question

I am at my limit at the moment as I can send e-mail (exchange 2010) but i have no idea how to add new lines

 

the command I am using is 

Send-MailMessage -From "user1@domain.com" -To "user2@domain.com" -Subject 'Subject Line' -Body 'The quick brown fox <linebrake>jumps over the lazy dog' -SmtpServer "mail.server.com"

how do i add a line brake at the <linebrake> ... it can be HTML or plain text. I have tried just about everything and i cannot make it happen. 

5 answers to this question

Recommended Posts

  • 0

`n is the PowerShell's newline special character. If you need a carriage return it's `r.

 

Combine them if you want a space between lines: `r`n. 

 

This link does a good job at explaining it: https://ss64.com/ps/syntax-esc.html

 

If you want to use <br> you'll need to specify -BodyAsHtml on Send-MailMessage.

  • Like 1
  • 0
  On 15/05/2017 at 15:32, Stokkolm said:

`n is the PowerShell's newline special character. If you need a carriage return it's `r.

 

Combine them if you want a space between lines: `r`n. 

 

This link does a good job at explaining it: https://ss64.com/ps/syntax-esc.html

 

If you want to use <br> you'll need to specify -BodyAsHtml on Send-MailMessage.

Expand  

Didn't know that powershell used " ` " as escape character, thanks!

  • 0
  On 15/05/2017 at 15:37, Seahorsepip said:

Didn't know that powershell used " ` " as escape character, thanks!

Expand  

Not a problem. It uses ` instead of \ because Windows uses \ in it's folder pathing (e.g. C:\Windows\system) whereas *nix systems use /, so no conflict for them. 

  • Like 1
This topic is now closed to further replies.