Sending Email with Large Attachment (20-50MB) via SMTP in PowerShell – "An existing connection was forcibly closed by the remote host" Error

huangapple go评论75阅读模式
英文:

Sending Email with Large Attachment (20-50MB) via SMTP in PowerShell - "An existing connection was forcibly closed by the remote host" Error

问题

I'm attempting to send an email using PowerShell, and I need to attach a zip file that's around 20-50MB in size. I'm encountering an issue with the Send-MailMessage cmdlet where I'm getting the following error:

Send-MailMessage : Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
$from = "murat@abc.com"
$to = "azamat@abc.com"
$subject = "Report is attached. Please take a look!"
$body = "This is a report email "

$attachment = "report.txt"
$encoding = [System.Text.Encoding]::UTF8

Send-MailMessage -From $from -To $to -Subject $subject -Body $body -Encoding $encoding -Attachments $attachment -SmtpServer "smtp.abc.com"

I suspect that the issue might be related to the large attachment size, but I'm not sure how to handle it. Is there a way to properly send a large attachment via an SMTP server using PowerShell?

英文:

I'm attempting to send an email using PowerShell, and I need to attach a zip file that's around 20-50MB in size. I'm encountering an issue with the Send-MailMessage cmdlet where I'm getting the following error:

Send-MailMessage : Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
$from = "murat@abc.com"
$to = "azamat@abc.com"
$subject = "Report is attached. Please take a look!"
$body = "This is a report email "

$attachment = "report.txt"
$encoding = [System.Text.Encoding]::UTF8

Send-MailMessage -From $from -To $to -Subject $subject -Body $body -Encoding $encoding -Attachments $attachment -SmtpServer "smtp.abc.com"

I suspect that the issue might be related to the large attachment size, but I'm not sure how to handle it. Is there a way to properly send a large attachment via an SMTP server using PowerShell?

答案1

得分: 2

最有可能的原因是附件的大小,因此您看到了“远程主机强制关闭”的错误。服务器已开始接收消息,确定大小过大,然后关闭了连接。

您是否已经检查了如果附件较小是否会出现相同的问题?

正如vonPryz提到的,电子邮件并不是发送大附件的理想方法,而且20MB是许多电子邮件提供商的常见大小限制,因此值得检查您的提供商配置了多大的限制。如果您通过自己的邮件服务器发送,则可能可以增加该限制,但请记住,如果这些电子邮件被发送给外部人员,那么他们可能无法接收。

例如,快速查看在线信息显示,Gmail当前的限制为25MB,Outlook.com的限制为34MB。

还要记住,大小限制是基于编码后的大小,而不是计算机上文件的大小。通常,一封附件的大小在通过服务器进行电子邮件传输后可能会增加三分之一。因此,如果您有一个24MB的文件,通过服务器传输的编码电子邮件可能达到32MB。这里有一个很好的解释:https://superuser.com/questions/1139323/why-is-the-size-of-my-email-about-a-third-bigger-than-the-size-of-its-attached-f

英文:

The most likely cause is due to the size of the attachment, hence the "forcibly closed by the by remote host" error you're seeing. The server has started receiving the message, determined the size to be too large, and closed the connection.

Have you checked whether you get the same issue if the attachment is smaller?

As vonPryz has mentioned, email isn't really the ideal method for sending large attachments, and 20MB is quite a common size limit with many email providers, so it's worth checking what your provider has it configured as. If you're sending via your own mail server then you may be able to increase that limit, but keep in mind if those emails are being sent onto someone external then THEY might not be able to receive them.

For example, a quick look online shows that Gmail's current limit is 25MB and Outlook.com's is 34MB.

Also keep in mind that the size limit is based on the encoded size, NOT the size of the file(s) on your computer. Typically you can expect to see the size of the attachment increase by as much as a third once it has been encoded for email transmission. So if you have a 24MB file, the encoded email going through the server could well be 32MB. There's a good explanation of why here https://superuser.com/questions/1139323/why-is-the-size-of-my-email-about-a-third-bigger-than-the-size-of-its-attached-f

huangapple
  • 本文由 发表于 2023年6月1日 02:33:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定