在PowerShell电子邮件压缩pic长度的html主体中嵌入图像

时间:2016-07-19 19:55:28

标签: html email powershell

我使用以下脚本发送邮件。

{

$imgfile = “C:\Users\Rammy\Desktop\Pic.png”
$SMTPServer = “smtp.gmail.com”
$SMTPPort = “587”
$Username = “motheramesh486@gmail.com”
$Password = “xxxxxxxx”

$to = “motheramesh486@gmail.com”
$cc = “motheramesh486@gmail.com”
$subject = “Email Subject”
$body = @”
<html>
<body>
<img src="cid:image1.png">
</body>
</html>
“@

$attachment = New-Object System.Net.Mail.Attachment($imgfile)

$attachment.ContentDisposition.Inline = $True
$attachment.ContentDisposition.DispositionType = “Inline”
$attachment.ContentType.MediaType = “image/png”
$attachment.ContentId = ‘image1.png’

$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.IsBodyHtml = $True

$message.body = $body
$message.to.add($to)
$message.cc.add($cc)
$message.from = $username
$message.attachments.add($attachment)

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username,         $Password);

$smtp.send($message)
write-host “Mail Sent”

$attachment.Dispose();
$message.Dispose();
}

我可以使用上面的脚本发送邮件,但它压缩了pic长度。 图片有1500x5000像素,现在我看到图片长度被压缩,它会扭曲图片。 但是,当我通过outlook手动插入图片并发送电子邮件时,它看起来非常好。

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

Click here to see how the image looks like in mail

Click here for original image

0 个答案:

没有答案