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:of fice" 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@5 xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stro ke><v:form ulas><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:p ath o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:p ath><o:loc k v:ext="edit" aspectratio="t"></o:lock>< /v:shapety pe><v:shap e 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:shap e></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>'
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
<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@5
<v:imagedata src="-- link to picture --"></v:imagedata></v:shap
<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>'
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"
ASKER
Hi, I tried it but still the same.
Output:
Hello $firstname,
your account expires on $accountexpires,
please change your password!
HelpDesk
Output:
Hello $firstname,
your account expires on $accountexpires,
please change your password!
HelpDesk
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks a lot , I completely forgot about + .