Avatar of E=mc2
E=mc2
Flag for Canada asked on

Modfiy scriopt to embed txt into body of email

I would like to modify the following script so that it will embed the contents of the source file in the body of the email:

The source file is at:

C:\Users\User\Desktop\File\file.txt


[code][/###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
      $splat = @{
            From =                  'email1@email.com'
            To =                  Get-Content -Path ( Join-Path $PSScriptRoot 'DistList..txt')
            SmtpServer =      'smtp.smtp.com'
            Subject =            $subject
            body =                  $MessageBody
            BodyAsHtml =      $true
      }
      Send-MailMessage @splat
###PROGRAM END###code]
PowershellWindows 10Scripting Languages

Avatar of undefined
Last Comment
E=mc2

8/22/2022 - Mon
oBdA

Since you want to send this as html, you need to tell more, especially if you want to add to $MessageBody, and if so, what are its contents?
E=mc2

ASKER
The message body is only test which resembles something like this:

ORDERS:

Number: 12345

Item 1: ABC: 789456153212, Desc: adkl;fjakl;djfklajkl;j;afss, Qty: 500, Price: $1.00
Item 2: ABC: 456456545466, Desc: jakldfjakl;jdfl;kajflkjdl;s, Qty: 400, Price: $2.00
Item 3: ABC: 125212313123, Desc: akljdfkl;ajdflkjakl;djsf;d, Qty: 300, Price: $3.00
Item 4: ABC: 456465456466, Desc: aabblblbllllalalllalalllllla, Qty: 200, Price: $4.00
Item 5: UPC: 123456545564, Desc: uiuadsfjal;fdjal;kjdfl;akj, Qty: 100, Price: $5.00
Total: $0000.00
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
E=mc2

ASKER
Thanks oBda, I realliy don't need BodyAsHtml..  let me try the script, many thanks,
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
E=mc2

ASKER
oBdA, thanks again, just ran the script, however it does not respect the different lines shown in the data I provided..
In the body, it should reflect a new line, when the new line appears in the raw data.
Any changes?
E=mc2

ASKER
It seems like Outlook was removing extra line breaks...…
Not sure how to force this in the script...…
Perhaps it's not possible..
E=mc2

ASKER
Thank you.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.