1

When i'm trying to send a file which is of size 100mb as email attachment, i'm getting system.outofmemoryexception. With the same code i was able to send the attachment which is having size of 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);
}

And in wed config file added following lines

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

<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
</system.webServer>
chinna g
  • 405
  • 1
  • 4
  • 6
  • 1
    Welcome to Stack Overflow! Did you take a look at https://stackoverflow.com/questions/16684941/how-to-email-large-files-using-c-sharp-windows-application? – Max Jan 09 '19 at 11:46
  • 2
    Possible duplicate of [How to email large files using c# windows application](https://stackoverflow.com/questions/16684941/how-to-email-large-files-using-c-sharp-windows-application) – Chris Moschini Jan 09 '19 at 11:53
  • win form will differ than email, i guess @Max – Vishwa Ratna Jan 09 '19 at 11:54
  • Sounds like you are out of memory... Have you investigated whether this is actually the case? E.g. open task manager and see how much memory is available. – usr Jan 09 '19 at 14:25
  • 1
    This seems to be ASP.Net so is running on a web server, why not email a download link instead? – Alex K. Jan 09 '19 at 14:53
  • 8
    Don't send emails with 100 MB attachments. I don't know anyone who could *receive* such a mail. Use FTP or any other file exchange platform for this and send download link instead. – LocEngineer Jan 09 '19 at 15:10
  • Might also be relevant: https://stackoverflow.com/questions/6434506/maximum-ram-avaiable-for-an-asp-net-app – Progman Jan 09 '19 at 15:58
  • gmail has 25mb limit which is quite big. No point sending 100 mb file. use ftp instead – Gauravsa Jan 10 '19 at 06:15

0 Answers0