Extra SPACES in Subject Line of email

I have a daily script that runs and sends an email to users with passwords soon to expire. The issue I have is in the “Subject line” of the email. The subject line includes in the “user name” and comment about expiring in 10 days or less. Between the user name and the comment includes a lot of extra spaces.


$LastsetDate = (get-qaduser -includeallproperties $user).passwordlastset

$Newdate = $LastsetDate.AddDays(90)

start-sleep -s 2

$subject = $user + “your password will expire in 10 days or less”

$smtpServer = “smtp.nnnn.com

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “IThelpdesk_NoReply@nnnn.com


$msg.Subject = $subject

$msg.Body = $Message


$UserCount ++


Hi RJP - Please trim the user name.


$subject = $user.ToString().Trim() + " your password will expire in 10 days or less"



Hi Kiran - That worked! TY!