Extra SPACES in Subject Line of email

Welcome Forums General PowerShell Q&A Extra SPACES in Subject Line of email

This topic contains 2 replies, has 2 voices, and was last updated by

RJP
 
Participant
2 weeks, 5 days ago.

  • Author
    Posts
  • #132569
    RJP

    Participant
    Points: 14
    Rank: Member

    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.To.add($user)

    $msg.Subject = $subject

    $msg.Body = $Message

    $smtp.Send($msg)

    $UserCount ++

     

  • #132572

    Participant
    Points: 282
    Helping Hand
    Rank: Contributor

    Hi RJP – Please trim the user name.

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

     

    • #132575
      RJP

      Participant
      Points: 14
      Rank: Member

      Hi Kiran – That worked! TY!

You must be logged in to reply to this topic.