在C#中将100mb文件作为电子邮件附件发送时获取system.outofmemoryexception

时间:2019-01-09 11:34:37

标签: c# smtpclient

当我尝试发送大小为100mb的文件作为电子邮件附件时,我正在获取system.outofmemoryexception。使用相同的代码,我可以发送大小为12mb的附件

using (var sendemail = new SmtpClient())
{
    //code with smtp host, To address etc goes here

     sendemail.Timeout = 500000;

    msg.Attachments.Add(new 
      System.Net.Mail.Attachment(@"C:\data.zip")); //data.zip is the attachment stored on my C drive

    sendemail.Send(msg);
}

然后在wed配置文件中添加了以下几行

<system.web>
  <httpRuntime targetFramework="4.6" maxRequestLength="2097152" />
</system.web>

<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
</system.webServer>

0 个答案:

没有答案