Solved

How to define powershell variable in HTML mail body

Posted on 2010-11-08
4
1,769 Views
Last Modified: 2012-05-10
Hello,

Please advice, I tried to input powershell variable $accountexpires into HTML body, but it always shows as a HTML string. I tried to close it into "", '' etc..
But shows error or string in email.

BR

$MailMessage.Body = '
 <HTML xmlns:o = "urn:schemas-microsoft-com:office:office" xmlns:v = "urn:schemas-microsoft-com:vml">
    <head>
      <style type="text/css">
       
      </style>
    </head>
    <body>
<H3 style="MARGIN: 10pt 0cm 0pt"><SPAN style="mso-no-proof: yes"><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape style="WIDTH: 1945px; HEIGHT: 317px; VISIBILITY: visible; mso-wrap-style: square" id=obrázek_x0020_2 o:spid="_x0000_i1028" type="#_x0000_t75">
<v:imagedata src="-- link to picture --"></v:imagedata></v:shape></SPAN></H3>
      <p><font face="verdana" size="2">Hello $firstname,<BR /> your account expires on $accountexpires, <BR />please change your password!<BR /><BR />HelpDesk</font></p>
     
    </body>
  </html>'
0
Comment
Question by:Radim88
  • 2
  • 2
4 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 34082557
take the html code and put it in a file (i.e. body.html), then your powershell code should look something like this:$MailMessage.Body = get-content "body.html"
0
 

Author Comment

by:Radim88
ID: 34082748
Hi, I tried it but still the same.
Output:

Hello $firstname,
your account expires on $accountexpires,
please change your password!

HelpDesk
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 125 total points
ID: 34082874
i thought u meant something else.


here's the right code:
$MailMessage.Body = '
 <HTML xmlns:o = "urn:schemas-microsoft-com:office:office" xmlns:v = "urn:schemas-microsoft-com:vml">
    <head>
      <style type="text/css">
       
      </style>
    </head>
    <body>
<H3 style="MARGIN: 10pt 0cm 0pt"><SPAN style="mso-no-proof: yes"><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape style="WIDTH: 1945px; HEIGHT: 317px; VISIBILITY: visible; mso-wrap-style: square" id=obrázek_x0020_2 o:spid="_x0000_i1028" type="#_x0000_t75">
<v:imagedata src="-- link to picture --"></v:imagedata></v:shape></SPAN></H3>
      <p><font face="verdana" size="2">Hello'+ $firstname+',<BR /> your account expires on +'$accountexpires'+, <BR />please change your password!<BR /><BR />HelpDesk</font></p>
     
    </body>
  </html>'

Open in new window

0
 

Author Closing Comment

by:Radim88
ID: 34082903
Thanks a lot , I completely forgot about + .
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now