• 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. 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
`n

or

<br>

Should do the job.

When using <br> you might need to use the following parameter:

-BodyAsHtml

 

Moved the topic to the programming sub forum.

Link to comment
Share on other sites

  • 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
Link to comment
Share on other sites

  • 0
4 minutes ago, 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.

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

Link to comment
Share on other sites

  • 0
Just now, Seahorsepip said:

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

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
Link to comment
Share on other sites

This topic is now closed to further replies.