I have a code that sends an email using System.Net.Mail.MailMessage. Unfortunately, the recipient's Outlook is blocking images in the signature. Images are blocked only when sending using this script. Could someone tell me may I avoid this? Thank You very much.
I tried following things:
- IsBodyHtml = 'true' /'false'
- Different users
My code:
Connect-VIServer -server srv01.xxxxx.co.com
$myCol = @()
ForEach ($Cluster in Get-Cluster)
{
ForEach ($vmhost in ($cluster | Get-VMHost))
{
$VMView = $VMhost | Get-View
$VMSummary = “” | Select ClusterName, HostName, CPUSockets, CoresProCPU, VMs
$VMSummary.HostName = $VMhost.Name
$VMSummary.ClusterName = $Cluster.Name
#$VMSummary.MemorySizeGB = $VMview.hardware.memorysize / 1024Mb
$VMSummary.CPUSockets = $VMview.hardware.cpuinfo.numCpuPackages
$VMSummary.CoresProCPU = ($VMview.hardware.cpuinfo.numCpuCores)/2
$VMSummary.VMs = (get-vm -location $VMhost.Name| measure-object).count
$myCol += $VMSummary
}
}
#$myCol | Sort-Object -Property HostName| Format-Table
################################
# Mail Report Setup Variables #
################################
[string]$ReportEmailFromAddress = 'Lic@xxxxx.com'
[string]$ReportEmailToAddress = 'n@xxxxx.com'
#[string]$ReportEmailCCAddress = 'd@xxxxx.com'
[string]$ReportEmailSubject = "Lic" + ' ' + (Get-Culture).DateTimeFormat.GetMonthName((Get-Date).AddMonths(-1).Month) + ' ' + (Get-Date).AddMonths(-1).ToString('yyyy')
[string]$ReportSMTPServer = 'remote.xxxxx.com'
[int32]$ReportSMTPPort = '25'
[boolean]$ReportSMTPServerEnableSSL = $True
################################
# Mail the Report #
################################
function MailReport {
$message = New-Object System.Net.Mail.MailMessage
$mailer = New-Object System.Net.Mail.SmtpClient ($ReportSMTPServer, $ReportSMTPPort)
$message.IsBodyHtml = 'true'
$message.From = $ReportEmailFromAddress
$message.To.Add($ReportEmailToAddress)
# $message.CC.Add($ReportEmailCCAddress)
$message.Subject = $ReportEmailSubject
$htmlhead = "<html>
<style>
BODY{font-family: Arial; font-size: 12pt;}
H1{font-size: 22px; font-family: 'Arial,sans-serif;}
H2{font-size: 18px; font-family: 'Arial,sans-serif;}
H3{font-size: 16px; font-family: 'Arial,sans-serif;}
TABLE{border: 1px solid black; border-collapse: collapse; font-size: 12pt;text-align:center;}
TH{border: 1px solid #969595; background: #dddddd; padding: 5px; color: #000000;text-align:center;}
TD{border: 1px solid #969595; padding: 5px; text-align:center;}
td.pass{background: #B7EB83;}
td.warn{background: #FFF275;}
td.fail{background: #FF2626; color: #ffffff;}
td.info{background: #85D4FF;}
</style>
<body>"
$htmltail = "</body></html>"
$bodytextstart = 'S'
$bodytextend = "
<br><p style = 'font-family:'Arial', sans-serif; font-size: 13px;'>
E-Mail: <a href='mailto:xxx@xxxxx.com'>xxx@xxxxx.com</a><br>
<a href='http://www.xxxxx.com/'>www.xxxxx.com</a><br><br>
<img src='https://exchange.xxxxx.com/Signature/xxxxx_Slogan.jpg' alt='xxxxx Slogan'><br><br>
<a href='https://www.instagram.com/xxxxx/'><img src='https://exchange.xxxxx.com/Signature/Insta.png' title='xxxxx Instagram' alt='Instagram'></a>
<a href='https://www.instagram.com/xxxxx/'>@xxxxx</a> <a href='https://www.facebook.com/xxxxx/'><img src='https://exchange.xxxxx.com/Signature/FB.png' title='xxxxx FB' alt='FB'></a> <a href='https://www.facebook.com/xxxxx/'>@xxxxx xxx</a></strong></p>
"
$Table = $myCol | Sort-Object -Property HostName| ConvertTo-Html -Fragment
$body = $htmlhead + $bodytextstart + $Table + $bodytextend + $htmltail
$message.Body = $body
$mailer.send(($message))}
MailReport