Hi,
I have issues adding the image embedded to the email body, it is not showing.
Please help
Script
Get-VM | Get-CDDrive | select @{N="Folder";E={$_.Parent.Folder.Name}}, @{N="VM";E={$_.Parent.Name}}, @{N='ISO Path';E={$_.IsoPath}} | ConvertTo-Html <H2> All the ISO`s has been unmounted from the below listed VMs </H2>" -Property Folder, VM, 'ISO Path' -PostContent $post > $reportlocation
#Send Email Configuration
$att = "<br/><img src='D:\logo.png'/><br/>"
$body = Get-Content $reportlocation -Raw
Write-Host "Report has exported as HTML file" : $reportlocation
Send-Mailmessage -From $FromAddress -To $ToAddress -Subject $Subject -Body $att+$body -BodyAsHtml -Attachments $reportlocation1 -SmtpServer $SMTPServer
Write-Host "Report has been sent by E-mail to " $ToAddress " from " $FromAddress
Looks like this inline image via a CID is not that straightforward after all.
I reverted to using David Wyatt's function from Send-MailMessage function with support for inline attachments
Attached the script (and .png) I used.
Now the report, at least for me, seems to work correctly in all my email clients.
Give it a try.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure I understand the question.
What image are you talking about?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I have a company logo in png or jpeg format.
I would like to add this png or jpeg as a inline in the body of email
I normally do this as follows
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
'@
$whatever = Get-Process | select -First 5 Name,Handles,WS |
ConvertTo-Html -Fragment -As Table -PreContent '<h2>My Report</h2>' |
Out-String
$attachment = Get-Item -Path C:\temp\pic.jpg
$img = @'
<html>
<body>
<img src="cid:image1"><br>
</body>
</html
'@
$sMail = @{
To = 'luc@local.lab'
From = 'luc@local.lab'
SMTPServer = 'mail.local.lab'
Subject = "Test logo"
BodyAsHTML = $true
Body = ConvertTo-HTML -Head $Header -Body "$img $whatever" | Out-String
Attachments = $attachment.FullName
}
Send-MailMessage @sMail
This results in something like this
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Looks like this inline image via a CID is not that straightforward after all.
I reverted to using David Wyatt's function from Send-MailMessage function with support for inline attachments
Attached the script (and .png) I used.
Now the report, at least for me, seems to work correctly in all my email clients.
Give it a try.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much LucD. it worked perfectly