VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to add image to report

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.

2019-09-12_17-58-57.png

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Not sure I understand the question.
What image are you talking about?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I normally do this as follows

$Header = @'

<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

2019-09-12_13-59-29.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am not able to get the image displayed in the email. I am getting the as below

Also I have attached the script for your reference

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.

2019-09-12_17-58-57.png

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD. it worked perfectly Smiley Happy

Reply
0 Kudos