I am trying to create a powershell script (version 2.0) to send inline images, as explained here. But something does not seem to work, or is maybe outdated or incorrect.
The following is a complete test script
$msg = new-object Net.Mail.MailMessage
$image = "testImage.png"
$imageFull = "D:\Testing\testImage.png"
$attachment = New-Object System.Net.Mail.Attachment –ArgumentList $imageFull
$body=@"
<html>
<body>
<img src="cid:$image">
</body>
</html>
"@
which only uses an example image, and creates the following error:
The string starting:
At D:\Testing\Data\Powershell\LoadRunner\LRtestError.ps1:14 char:1
+ <<<< "@
is missing the terminator: ".
At D:\Testing\Data\Powershell\LoadRunner\LRtestError.ps1:16 char:1
+ <<<<
+ CategoryInfo : ParserError: (@
:String) [], ParseException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
What is going on? Why is this error created? How to fix it?
NOTE:
- If you comment out the
System.Net.Mail.Attachmentline, no error is created!! - Used OS: Windows Server 2008 R2 Standard (64-bit)
Full version table:
$psversiontable: Name Value ---- ----- CLRVersion 2.0.50727.5485 BuildVersion 6.1.7601.17514 PSVersion 2.0 WSManStackVersion 2.0 PSCompatibleVersions {1.0, 2.0} SerializationVersion 1.1.0.1PSRemotingProtocolVersion 2.1
Windows PowerShell (x86)) as administrator. I change into the directory containinf the script and then I start it as.\testscript.ps1.