We help IT Professionals succeed at work.

Powershell formatting using send-mailmessage

rakkad
rakkad asked
on
585 Views
Last Modified: 2018-02-02
I have created a powershell script that uses send-mailmessage and uses get-content to read in a file in html, however,  I want the message body to contain text and use the get-content to get the file so, it should say something like:-

Please see attached file

and then use the get-content to retrieve a html file

Hope this makes sense

Thanks




T
Comment
Watch Question

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
David Johnson, CDSimple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
you can't mix text/html with powershell.  You need to not use get content but simply use the -attachment option in your send-mailmessage i.e.
-Attachments "data.csv"
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
David, you can mix plain text and HTML, it just doesn't look that good.
David Johnson, CDSimple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You misunderstood.. you cannot run a powershell script to a mail message and execute it in the mail message.. the body of an email message is text i.e.
start-process cmd.exe in the message will not ever execute
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
The question could be read indeed that way - sending over PowerShell code to get the content of the file. But that does not make much sense, so I went with the more useful interpretation.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
I've doubts about what has been really meant here, so summarizing the available opitions.

Send the text file as attachment is not much different than to send it over as text in the HTML body, but doing the later is better for immediate review. Both options require the complete text to be stored in the local PST or OST, and if Exchange 2013 is used, one single time on the server (with auto dedup), with older Exchanges storing a copy for each receiver.

Sending over a PS script as attachment is possible but requires an inacceptable weakening of Outlook security settings to allow execution. PS scripts in email are already used for attacks.

Having local VBA code in Outlook requires some sophisticated setup, and to allow macro execution (again a security risk, though it can be restricted much better to be "secure"). Then a mail can contain a certain subject, some keywords in the body or whatever, and the file name to display. A button to call the (local) macro, e.g. located in the Quick Access bar, can be used to run the code to display the file.
This would keep the file in a single location, not having it contained in any mail. But the effort is worth it only for very large files, IMHO.
David Johnson, CDSimple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
answered

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions