Question:
I am working on changingSend-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.
PoSh Code:
Answer:
You don’t need to create a new object if you’re just interested in interpolating the Inner ExceptionMessage
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:
You cannot call a method on a null-valued expression.
If you have better answer, please add a comment about this, thank you!