4

我有一个嵌入(不附加)图片并发送电子邮件的 powershell 脚本。图片现在已增加到 1500x5000 像素,现在我看到图片长度被压缩并且扭曲了图片。但是,当我通过 Outlook 手动插入图片并发送电子邮件时,它看起来还不错。

如果我保存图片然后通过油漆或其他方式打开它,图片打开正常。它只是在电子邮件中看起来被压缩了。有人知道那里可能发生什么吗?

{
    $Application = "C:\Autobatch\Spotfire.Dxp.Automation.ClientJobSender.exe"
    $Arguments  = "http://s.net:8070/spotfireautomation/JobExecutor.asmx C:\Autobatch\HourlyStats.xml"
    $CommandLine = "{0} {1}" -f $Application,$Arguments
    invoke-expression $CommandLine
    $file = "C:\Autobatch\HourlyStats.png"
    $smtpServer = "smtp.staom.sec.s.net"
    $att = new-object Net.Mail.Attachment($file)
    $att.ContentType.MediaType = “image/png”
    $att.ContentId = “pict”
    $att.TransferEncoding = [System.Net.Mime.TransferEncoding]::Base64
    $msg = new-object Net.Mail.MailMessage
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $msg.Attachments.Add($att)
    $msg.From = "d.k@s.com"
    $msg.To.Add("r.p@p.com")
    $msg.Subject = "Voice and Data Hourly Stats"
    $msg.Body = "<p style=’font-family: Calibri, sans-serif’&gt;
              Voice and data hourly stats details<br />
             </p>
             <img src='cid:pict'/>"
    $msg.IsBodyHTML = $true
    $smtp.Send($msg)
    $att.Dispose()
    invoke-expression "DEL $file"
}

这是电子邮件中的图片。压缩图片

4

4 回答 4

2

尝试添加

$att.ContentDisposition.Inline = $true

我怀疑某些默认行为正在幕后发生,只是脚本和 Outlook 之间不一致。

更多信息在这里

于 2013-08-28T19:09:25.767 回答
2

您的电子邮件客户端似乎将内容缩小到某个最大大小。尝试放入<img src='cid:pict'/>一个<div>环境:

<div style="overflow: scroll">
  <img src='cid:pict'/>
</div>

此外,如果您有任何方法可以检索图像的实际像素宽度,您可以尝试相应地设置<img>标签的 CSS。

于 2016-07-25T13:57:54.257 回答
0

通过问这个问题,我可能听起来像个菜鸟,但出于好奇,如果您有手动方式通过 Outlook 发送电子邮件,为什么不制作一个脚本来发送带有所需屏幕截图的自动电子邮件呢?

IDK,如果这可能对您有所帮助,但我很久以前就制作了这个脚本,用于我的日常报告目的。嗯,它符合要求。在这里分享一下,供大家参考。

#In this segment, I navigate IE to my specific destination, screen which I want to capture.

$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true;
$Website = $ie.navigate('https://put.your.URL.here')
while($Website.Busy){Start-Sleep -Seconds 5}

#In this class, script captures the screen, once, all the data loading is over.
$file = "C:\Users\Desktop\$(Get-Date -Format dd-MM-yyyy-hhmm).bmp"
#P.S. I made it to save that screenshot with current date and time format. Also, default screenshot will be captured in .BMP format. 

Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing

$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$width = $Screen.width
$Height = $Screen.Height
$Left = $Screen.Left
$Right = $Screen.Right
$Top = $Screen.Top
$Bottom = $Screen.Bottom

$bitmap = New-Object System.Drawing.Bitmap $width, $Height

$Graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$Graphics.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)

$bitmap.Save($File) 

Write-Output "Screenshot saved to:"
Write-Output $File

sleep -Seconds 5

#Sending an Email
$Outlook = New-Object -ComObject Outlook.Application
$mail = $Outlook.CreateItem(0)
$mail.To = "your.designated@emailid.com"
$mail.Subject = "Outstanding data as on $(Get-Date -Format dd-MM-yyyy)"
$mail.Body = "PFA screenshot, of all outstanding formation as on $(Get-Date -Format dd-MM-yyyy-hhmm)"
$mail.Attachments.Add($file)
$mail.Send()

我只是在回答这个问题,因为我尝试在上面发表评论,但我想,我的声誉得分太低了,无法做到这一点。希望这可能对您找到解决方法有所帮助。快乐编码。:)

于 2016-07-26T11:15:10.527 回答
-2

HTML 代码:<img src='cid:pict'/>应该是 -<img src='cid:pict'>只是删除正斜杠?

补充:此链接可能有助于讨论在电子邮件中嵌入图片。电子邮件签名中的 base64 编码图像。您可以尝试生成 base64 代码并将其放入电子邮件正文 HTML 中。

于 2013-07-08T23:03:01.820 回答