Is $expiredCert an array or does it hold a single object? If it's a single object, it appears to be either a PSObject or a certificate.
In your sendMail function you cast the value passed to the parameter $msgbody as a string. If you try to do this: $expiredCert.ToString()
the results probably don't look like what you expect.
I think what you want is to pass the results of this: $expiredCert | Out-String
to the sendMail function.
You might also try using the Send-MailMessage cmdlet instead of the Net.Mail.SMTPclient.
function sendMail([string]$msgbody) {
$props = @{
Server = "SMTP.myDomain.com"
From = "noreply@myDomain.com"
To = "myName@myDomain.com"
Subject = "SSL Certificate Expiring Soon"
Body = $msgbody
BodyAsHTML = $true
}
# Note: assumes port 25 is used,
# the connection is anonymous, and
# TLS (SSL) is not used.
Send-MailMessage @props
}