使用 C# ASP.NET 3.5 System.Net.Mail 发送大附件
我一直在尝试使用 C# ASP.NET 3.5 System.Net.Mail 发送一个大附件 (9 MB)。我读到 .NET 4.0 有一个错误不允许这样做,但 .NET 3.5 没问题。 .NET 4.0 发送电子邮件时失败附件大于 3MB
由于 .NET 3.5 在发送电子邮件后无法正确关闭会话,因此我在发送之前添加了这一行:
smtpClient.ServicePoint.MaxIdleTime = 2;
该行
smtpClient.Send(email);
仍然抛出此错误错误:
Exceeded storage allocation. The server response was: 5.3.4 Error: message file too big:
at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)
at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)
at System.Net.ClosableStream.Close()
at System.Net.Mail.MailWriter.Close()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
更改编码没有帮助。这会损坏附件:
email.Attachments[0].TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
有人可以帮忙吗?谢谢。
I have been trying to send a big attachment (9 MB) using C# ASP.NET 3.5 System.Net.Mail. I read that .NET 4.0 had a bug which doesn't allow this, but .NET 3.5 is fine.
.NET 4.0 Fails When sending emails with attachments larger than 3MB
Since .NET 3.5 doesn't close the session properly after an email is sent, I added this line before it's sent:
smtpClient.ServicePoint.MaxIdleTime = 2;
The line
smtpClient.Send(email);
is still throwing this error:
Exceeded storage allocation. The server response was: 5.3.4 Error: message file too big:
at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)
at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)
at System.Net.ClosableStream.Close()
at System.Net.Mail.MailWriter.Close()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Changing the encoding doesn't help. This corrupts the attachment:
email.Attachments[0].TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
Could someone please help? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这告诉您需要知道的一切:服务器不允许发送该大小的附件。您的代码没有任何问题,至少不是因为 .NET 中的错误或类似的问题。您链接的与 .NET 中的错误相关的错误消息与您收到的消息非常不同。这是无关的。
That tells you everything you need to know: The Server dissallows sending attachments of that size. There's nothing wrong with your code, at least not because of a bug in .NET or something like that. The error message you link related to a bug in .NET is very different from what you are getting. It's unrelated.