gpt4 book ai didi

powershell - Send-MailMessage 使附件变大

转载 作者:行者123 更新时间:2023-12-05 04:33:25 26 4
gpt4 key购买 nike

我有一个 Powershell 脚本来发送带有压缩文件附件的电子邮件。在服务器上,zip 文件大约为 16MB。这些电子邮件被我们的 Exchange 服务器拒绝,因为附件太大。我们有 20MB 的限制。 Exchange 服务器将附件显示为 21MB。这可能是什么原因?

这是脚本:

$baseDir = "\\999.999.999.999\xxxxx\yyyy"

#email settings
$MailServer = "mail.#######.com"
$eMailSender = 'xxx@######.com'
$Recipient = 'yyy@######.com'
$Subject = "Files available"
$BodyBase = "Hello,`n`nattached are the files`n"

$zipFileBaseName = "xyzfiles" + (Get-Date).ToString("yyyyMMdd")
$zipFiles = $baseDir + "\" + $zipFileBaseName + "*"
$NumZips = (Get-ChildItem $zipFiles).count

$i = 0
foreach($zip in Get-ChildItem $zipFiles)
{
$i++
$Body = "This is email " + $i + " of " + $NumZips + ". (" + $zip.Name + ")"
$Body = $BodyBase + $Body

Send-MailMessage -SmtpServer $MailServer -from $eMailSender -To $Recipient -Subject $Subject -Body $Body -Attachments $zip.Fullname

}

文件夹中zip文件的数量每天都不一样。有时大小只有 10MB 左右。在这种情况下,将发送电子邮件。

有什么想法可以使附件增加 5MB 吗?

谢谢,
迈克尔

最佳答案

这不是您期望的答案,但这就是 SMTP 的工作方式。

此片段来自 Wikipedia给出了正确的解释:

Also note that all these size limits are based, not on the original file size, but the MIME-encoded copy. The common Base64 encoding adds about 37% to the original file size, meaning that an original 20MB file could exceed a 25MB file attachment limit.[11] A 10MB email size limit would require that the size of the attachment files is actually limited to about 7MB.

$arr = [byte[]]::new(16Mb)
[math]::Round($arr.Length / 1Mb) # => 16 Mb
$b64 = [Convert]::ToBase64String($arr)
[math]::Round($b64.Length / 1Mb) # => 21 Mb

关于powershell - Send-MailMessage 使附件变大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71433056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com