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
3 months, 3 weeks ago.

  • Author
    Posts
  • #132569
    RJP

    Participant
    Topics: 2
    Replies: 1
    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
    Topics: 0
    Replies: 78
    Points: 416
    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
      Topics: 2
      Replies: 1
      Points: 14
      Rank: Member

      Hi Kiran – That worked! TY!

The topic ‘Extra SPACES in Subject Line of email’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort