Link to home
Create AccountLog in
Avatar of Radim88
Radim88

asked on

How to define powershell variable in HTML mail body

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>'
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

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"
Avatar of Radim88
Radim88

ASKER

Hi, I tried it but still the same.
Output:

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

HelpDesk
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Radim88

ASKER

Thanks a lot , I completely forgot about + .