none
script to send email to user with their multiple email addresses RRS feed

  • Question

  • Hi 

    i got the script below which mainly email users about their current SMTP addresses (multiple ones) and ask them which one they dont need

    $Msg.To.Add($ToAddress)
    $Msg.Subject = "Email Addresses Clean up"
    $Msg.Body = $EmailBody
    $Msg.IsBodyHTML = $true
    $Smtp.Send($Msg)
    }
    # Define local Exchange server info for message relay. Ensure that any servers running this script have permission to relay.
    $ExchangeServer = "mail.hwl.com.au"
    $FromAddress = "it.helpdesk@hwle.com.au"
    # Import user list and information from .CSV file
    $Users = Import-Excel testfinalsmtpaddress.xlsx
    # Send notification to each user in the list
    Foreach ($User in $Users) {
    $ToAddress = $User.PrimarySmtpAddress
    $Name = $User.DisplayName
    $EmailAddresses = $User.EmailAddresses
    $EmailBody = @"
    <p style='font-size:10.0pt;font-family:"Arial",sans-serif'>Dear $Name.<o:p></o:p></span></p>
    <p style='margin-left:18.0pt;text-indent:-18.0pt;
    <![if !supportLists]><span style='font-size:10.0pt;
    font-family:Symbol;<span
    style='·<span style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </span></span></span><![endif]><span style='font-size:10.0pt;font-family:"Arial",sans-serif'>The
    following is a list of email addresses which are currently attached to your

    mailbox.<o:p></o:p></span></p>

    Email Addresses: $EmailAddresses

    The list of users with multiple smtp addresses have been generated and it is in excel format with each email have been displayed follow line break like this

    Problem is when I send an email to them using this function to display their email addresses Email Addresses: $EmailAddresses, all their smtp address does not display one by one with line break, it seem to combine them into one long line which make difficult for user to read. The excel spreadsheet which contains smtp addresses already got correct format 

    I just wonder if anyone know how can I overcome that?

    Name                                                                                                   Primary Email                                                EmailAddresses                                                                                                  

    Hung Nguyen

    hnnguyen@hwle.com.au

      jmarz@tresscox.com.au
      jmarz@lawsonsmith.com.au
      jmarz@abbotttout.com.au
      jmarz@hwl.com.au
      jmarz@cridlandsmb.com.au
      jmarz@hwlebsworth.com
      jmarz@hwlebsworths.com
      jmarz@hwlebsworths.com.au
      jmarz@ebsworths.com.au
      jmarz@kellyco.com.au
      jmarz@downingslegal.com.au
      jmarz@downings.com.au
      jmarz@hwlebsworth.com.au
      joseph.marz@hwle.com.au
      Joseph.Marz@hwlebsworth.com.au
      JMarz@ebsworth.com.au
      Joseph.Marz@hwl.com.au

    Tuesday, July 16, 2019 10:53 PM

All replies

  • Please fix you post. Code must be posted using the code posting tool provided. The example posted is not helpful. What you are asking is not understandable.

    We do not fix or customize code that you have found on the Internet.

    How to ask questions in a technical forum


    \_(ツ)_/

    Tuesday, July 16, 2019 11:00 PM
    Moderator
  • Your code is broken and incomplete making it even harder to understand what you are trying to do. You reference a function but there is no function.

    The email addresses are an array.

    The HTML will  not work correctly in an email body.


    \_(ツ)_/

    Tuesday, July 16, 2019 11:07 PM
    Moderator
  • # Import user list and information from .CSV file
    $Users = Import-Excel testfinalsmtpaddress.xlsx

    Please fix the code formatting  in order to help you. Looking at the code.. are you trying to import a csv ?

    Wednesday, July 17, 2019 7:34 PM
  • Try using the HTML style </br> between addresses. 
    • Proposed as answer by Gavin..S Thursday, July 18, 2019 6:02 PM
    Thursday, July 18, 2019 6:01 PM
  • $mailProps = @{
        From        = 'it.helpdesk@hwle.com.au'
        Subject     = 'Email Addresses Clean up'
        SmtpServer  = 'mail.hwl.com.au'
        Port        = 25
        BodyAsHtml = $true
    }
    
    $tmplt = @'
        <p style='font-size:10.0pt;font-family:Arial'>
            Dear {0}.
        </p>
        <p style='margin-left:18.0pt;text-indent:-18.0pt;'
            The following is a list of email addresses which are currently attached to your mailbox.
        </p>
        <p>
            {1}
        </p>
    '@
    
    $users = Import-Excel testfinalsmtpaddress.xlsx
    Foreach ($user in $users) {
        $body  = $tmplt -f $user.DisplayName, ($user.EmailAddresses -join '<br/>')
        Send-MailMessage $mailProps -To $user.PrimarySmtpAddress -Body $body
    }


    \_(ツ)_/


    Friday, July 19, 2019 9:09 AM
    Moderator
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, July 31, 2019 7:44 AM
    Moderator