powershell - Send-MailMessage 使附件变大

标签 powershell exchange-server

我有一个 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/

相关文章:

outlook - 从存储在 Exchange 中的 ContactInfo 获取 Smtp 电子邮件

android - 在 Activity 和 Service 之间交换对象

c# EWS 2007 地址为空

php - 是否可以为非您拥有的站点/服务器设置 cookie?

powershell - 包含不在 Powershell 中工作的运算符

string - 无法从 cmd.exe 运行 powershell 脚本?

c# - 使用 params 关键字从 PowerShell 调用 C# 函数

Powershell 默认参数集不起作用。错误

powershell - 使用 PowerShell 重命名一批文件而不丢失扩展名很困难

delphi - 从 Delphi 撰写 Outlook 2010 邮件的最简单方法?