Solved

How to define powershell variable in HTML mail body

Posted on 2010-11-08
4
1,793 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Tool to Build Android and iOS App 3 51
PowerShell Default Ports 3 23
Can't a Exchange 2010 snap-in in PowerShell script 25 11
CSS Logo Problem. 2 4
This article discusses how to create an extensible mechanism for linked drop downs.
A brief introduction to what I consider to be the best editor for PowerShell.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

919 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

19 Experts available now in Live!

Get 1:1 Help Now