2017-03-16 4 views
0
Send-MailMessage -From "Snoopy <[email protected]>" -To"Jermaine <[email protected]>" -Subject "Weekly Headcount Report" -Attachments "\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image001.png", "\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image002.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image003.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image004.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image005.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image006.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image007.png","\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image008.png" -SmtpServer "smtp.Brand.com" -Body '<html> <body> <img src="cid:2017 snerk Headcount_25311_image001.png"><br> <img src="cid:2017 snerk Headcount_25311_image002"><br> <img src="cid:2017 snerk Headcount_25311_image003.png"><br> <img src="cid:2017 snerk Headcount_25311_image004.png"><br> <img src="cid:2017 snerk Headcount_25311_image005.png"><br> <img src="cid:2017 snerk Headcount_25311_image006.png"><br> <img src="cid:2017 snerk Headcount_25311_image007.png"><br> <img src="cid:2017 snerk Headcount_25311_image008.png"><br> </body> </html>' -BodyAsHtml 

私は、これを動作させるためにさまざまな種類のものを試しましたが、これまでは赤いXを得ることができます。私はSOと他の場所で見つけたこのスクリプトの異なる修正を試みました。そのうちの1人にInlineAttachmentsがあり、powershellがそのパラメータにエラーを投げた。添付ファイルはそこにあり、壊れていないが、彼らは体に表示されていません。このスクリプトが画像の電子メールに赤いXを付ける理由

誰もが私のポストを指すと、それは私がそれに取り組む別の正確なコピーであると言うしたいので、私はPowerShellの5.0.10586.117

を持っている:

問題は、私はすでにhttps://gallery.technet.microsoft.com/scriptcenter/Send-MailMessage-3a920a6dで正確なコードをコピーしていますそれはうまくいかなかった。私は何のエラーもないが、私はまた、電子メールを取得していない。

$images = @{ 
    image1 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image001.png' 
    image2 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image002.png' 
    image3 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image003.png' 
    image4 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image004.png' 
    image5 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image005.png' 
    image6 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image006.png' 
    image7 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image007.png' 
    image8 = '\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\2017 snerk Headcount_25311_image008.png' 
} 

$body = @' 
<html> 
    <body> 
    <img src="cid:image1"><br> 
    <img src="cid:image2"><br> 
    <img src="cid:image3"><br> 
    <img src="cid:image4"><br> 
    <img src="cid:image5"><br> 
    <img src="cid:image6"><br> 
    <img src="cid:image7"><br> 
    <img src="cid:image8"><br> 
    </body> 
</html> 
'@ 

$params = @{ 
    InlineAttachments = $images 
    Body = $body 
    BodyAsHtml = $true 
    Subject = "Test email" 
    From = '[email protected]' 
    To = '[email protected]' 
    SmtpServer = 'smtp.Brand.com' 
} 

.\Send-MailMessage.ps1 @params 

私も試してみました:

$files = get-childitem "\\portal2010.Brand.com\sites\snerk HC\snerk HC Dashboards\2017 JE Headcount_files\" | where name -like "*.png" 
$body = @() 
$attachments = @() 
foreach($file in $files){ 
    $filename = [system.io.path]::GetFileName($file.FullName) 
    $attachments += $file.fullname 
    $body += "<br /><img src='" + $filename + "'/><br />" 
} 
$body = $body | Out-String 
Send-MailMessage -to "Jermaine <[email protected]>" -From "Snoopy <[email protected]>" -SmtpServer "smtp.Brand.com" -Subject "Test" -BodyAsHtml $body -Attachments $attachments 

レッドX年代をボディに。

これは、私の問題を解決しなかったという点を除いて、この質問と同じかもしれません。

+0

「添付ファイル」は電子メール本文内では使用できません。受信者への配信を目的とした独立ファイルです。 –

+0

1つのヒントこの問題を解決するために検索するキーワードを教えてください:Powershell Send-Mailmessageインライン添付。 – bluuf

+0

重複している可能性がありますが、他の投稿の回答は私のためには機能しません。 – Shenanigator

答えて

0

ここに私が最終的に得たところで働いています。

$SendTo = "[email protected]" 
$CCTo1 = "[email protected]" 
$CCTo2 = "[email protected]" 
$CCTo3 = "[email protected]" 
$CCTo4 = "[email protected]" 
$SMTPServer = "smtp.brand.com" 
$EmailFrom = "[email protected]" 
$EmailSubject = "Weekly HC Email" 

$Image2 = '\\portal2010.brand.com\sites\HC\HC Dashboards\2017 JE HC_files\2017 HC_10419_image002.png' 
$Image4 = '\\portal2010.brand.com\sites\HC\HC Dashboards\2017 JE HC_files\2017 HC_10419_image004.png' 
$Image6 = '\\portal2010.brand.com\sites\HC\HC Dashboards\2017 JE HC_files\2017 HC_10419_image006.png' 
$Image8 = '\\portal2010.brand.com\sites\HC\HC Dashboards\2017 JE HC_files\2017 HC_10419_image008.png' 

$Message = new-object Net.Mail.MailMessage 
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue 

$att2 = new-object Net.Mail.Attachment($Image2) 
$att2.ContentId = "att2" 
$att4 = new-object Net.Mail.Attachment($Image4) 
$att4.ContentId = "att4" 
$att6 = new-object Net.Mail.Attachment($Image6) 
$att6.ContentId = "att6" 
$att8 = new-object Net.Mail.Attachment($Image8) 
$att8.ContentId = "att8" 

$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
$body = ' 
     <img src="cid:att2" /><br/><br/> 
     <img src="cid:att4" /><br/><br/> 
     <img src="cid:att6" /><br/><br/> 
     <img src="cid:att8" /><br/><br/> 
' 

$Message.From = $EmailFrom 
$Message.To.Add($SendTo) 
$Message.Cc.Add($CCTo1) 
$Message.Cc.Add($CCTo2) 
$Message.Cc.Add($CCTo3) 
$Message.Cc.Add($CCTo4) 
$Message.Subject = $EmailSubject 
$Message.Body = $body 
$Message.IsBodyHTML = $true 
$Message.Attachments.Add($att2) 
$Message.Attachments.Add($att4) 
$Message.Attachments.Add($att6) 
$Message.Attachments.Add($att8) 
$smtp.Send($Message) 
関連する問題