Exceeded storage allocation. The server response was: 5.7.0 Our system detected an illegal attachment on your message.

If you are genearting zip file runtime in memory and sending mail at run time. and you faced the error as shown below:
Exceeded storage allocation. The server response was: 5.7.0 Our system detected an illegal attachment on your message.
Then to fix it, you have to do the following change in your code(Pls note I’ve used SharpZipLib and Memory Stream for sending an email at run time using gmail server):
[sourcecode language=”csharp”]
MemoryStream zipFileStream = new MemoryStream();
zipOutputStream = new ZipOutputStream(zipFileStream);
..
..
..
//read from stream and add to zipoutputstream code should go here

..
// Seek to begining — IF YOU DON’ ADD BELOW LINE IT Will give above error
zipFileStream.Seek(0, SeekOrigin.Begin);
mailMessage.Attachments.Add(new Attachment(zipFileStream, "myzipfile.zip"));
[/sourcecode]
if you’ve seen the above code. Below line says MemroyStream to seek to Begining of the stream, So when SMTP Server scans the file before sending it gets perfect file.
zipFileStream.Seek(0, SeekOrigin.Begin);
Happy Mailing!

4 Comments

  • Hi kiran,
    I am sending mail from SQL server 2005 and I’m getting same error there.
    Any idea about this scenario?
    Thanks
    Aakash

    • Hi Aakash,
      Can you post your script here?
      Thanks,
      Kiran Patil

  • sales process…
    […]Exceeded storage allocation. The server response was: 5.7.0 Our system detected an illegal attachment on your message. « A Place for C Sharpers/.Netters[…]…

  • if u upload file on internet and this error occur…….
    it mean your file extension not support………….

Comments are closed.