• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Format send email subject and body in powershell

Resolved: Format send email subject and body in powershell

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am working on changing Send-MailMessage formatting based on error or success. When there is an error, I would like to have the Subject and email Body text appear in red color. On success, I would like to change the Subject and email body text to Blue color. I was able to change the success email body to Blue color but the Subject and error email body does not work as expected.
error
PoSh Code:

Answer:

You don’t need to create a new object if you’re just interested in interpolating the Inner Exception Message you can simply use the Subexpression operator $( ).
For example:
$ErrorMessage would become the following in HTML:


As aside, using the .ToString() Method is definitely not recommended in this case, if the error you’re catching does not have an Inner Exception, you would get a new error.
For Example:
Would result in the following Error:

You cannot call a method on a null-valued expression.


If you have better answer, please add a comment about this, thank you!

powershell
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Resolved: GLMM with quasi-Poisson distribution

24/03/2023

Resolved: Is it possible to do custom preinstall scripts for npm from which one is run depending on the environment?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.