我想在 PowerShell 中為電子郵件生成嵌入式影像。但沒有運氣。我在用<p><img src='file:///C:\temp\Picture1.png' /></p>
# Email Subject Set Here
$subject="Your password will expire soon"
# Email Body Set Here, Note You can use HTML, including ?mages.
$body ="
<P style='font-size: 12pt; font-family: Arial Narrow;'>Dear FIRST_NAME,</P>
<P style='font-size: 12pt; font-family: Arial Narrow;'>The current password of the account 'PRINCIPAL_ACCOUNT_NAME' in the 'FQDN_DOMAIN' AD domain will expire at <B>PWD_EXPIRY_DATE</B>. Please change your password as soon as possible!</P>
<P style='font-size: 12pt; font-family: Arial Narrow;'><U>The new password must meet the following requirements:</U></P>
<UL>
<LI><P style='font-size: 12pt; font-family: Arial Narrow;'>Min. nr. of characters in a PWD = 'PWD_MIN_LENGTH characters' <BR><I>(The minimum number of characters to be used in a password)</I></P></LI>
<LI><P style='font-size: 12pt; font-family: Arial Narrow;'>Min. PWD age = 'PWD_MIN_AGE days' <BR><I>(Minimum number of days the new password must be used before it can be changed again)</I></P></LI>
<LI><P style='font-size: 12pt; font-family: Arial Narrow;'>Max. PWD age = 'PWD_MAX_AGE days' <BR><I>(Maximum number of days the new password can be used before it must be changed again)</I></P></LI>
<LI><P style='font-size: 12pt; font-family: Arial Narrow;'>Nr. of previous PWDs in history = 'PWD_HISTORY' <BR><I>(Number of new and unique passwords required before an old password can be reused again)</I></P></LI>
<LI><P style='font-size: 12pt; font-family: Arial Narrow;'>Password complexity enabled? = 'PWD_COMPLEX' <BR><I>(The new password must meet complexity requirements ONLY when configured to 'TRUE')</I></P></LI>
</UL>
<p><img src='file:///C:\temp\Picture1.png' /></p>
"
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High -Encoding $encoding
謝謝,
uj5u.com熱心網友回復:
不幸的是,直接參考您的 C:\ 上的檔案將不起作用(有太多的安全問題)并且Send-MailMessage不會撿起它。相反,您有 2 個選項,而且,盡管聽起來令人困惑和瑣碎,但很大程度上取決于您的目標電子郵件程式。
CID 影像嵌入
“老派”方法是將影像附加到電子郵件并使用 Content-ID (CID) 參考來鏈接兩者。如果您使用的是桌面Outlook 應用程式,這是首選方法。缺點是人們并不總是信任帶有附件的電子郵件,并且通過發送帶有附件的電子郵件會產生垃圾郵件/過濾的影響,因此有時這并不總是首選。此外,一些基于 Web 的電子郵件提供商也無法正確顯示影像。
$body = "<p>.... <img src='cid:Picture1.png' alt='Embedded Image'> ....</p>"
$file = 'C:\temp\Picture1.png'
Send-Mailmessage -Attachments $File -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High -Encoding $encoding
行內嵌入
行內嵌入將資料作為base64編碼資料嵌入(基本上將二進制影像資料更改為純文本),然后電子郵件客戶端/瀏覽器對其進行解碼。這意味著沒有附件,通常交付成功率更高。因為 web 中使用了 base64 編碼,所以所有基于 web 的電子郵件客戶端都可以毫無問題地顯示它們。缺點是 Outlook 2010 的桌面版本將顯示“默認阻止的影像”。
$file = Get-Content 'C:\temp\Picture1.png'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($file)
$EncodedText =[Convert]::ToBase64String($Bytes)
$body = "<p>.... <img src='data:image/png;base64,$EncodedText' alt='Embedded Image'> ....</p>"
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High -Encoding $encoding
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/482798.html
標籤:电源外壳
