使用 C# ASP.NET 3.5 System.Net.Mail 发送大附件

发布于 2025-01-06 01:13:18 字数 1134 浏览 3 评论 0原文

我一直在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三生一梦 2025-01-13 01:13:18

服务器响应为:5.3.4 错误:消息文件太大:

这告诉您需要知道的一切:服务器不允许发送该大小的附件。您的代码没有任何问题,至少不是因为 .NET 中的错误或类似的问题。您链接的与 .NET 中的错误相关的错误消息与您收到的消息非常不同。这是无关的。

The server response was: 5.3.4 Error: message file too big:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文