using smtp sent large file upto 60MB

Chris Angelico rosuav at gmail.com
Tue Dec 4 15:54:26 EST 2012


On Wed, Dec 5, 2012 at 2:41 AM, Laszlo Nagy <gandalf at shopzeus.com> wrote:
> If you still don't want to accept this suggestion, then go ahead! Write a
> program, send out 100MB emails, and you will see for yourself that it just
> doesn't work.

But be aware of a few things.

1) Converting 1MB of binary data into a MIME-packaged email is going
to result in about 2MB of text. (It's about 1.5MB for base 64
encoding, which is one of the most common used, plus a bit more for
structure around it, and rounding up, call it two meg.)

2) If that 2MB of text is stored as a Python text string, it could
potentially consume 4MB or 8MB of memory, unless you're on Python 3.3,
in which case it will be only 2MB..

3) That 2-8MB has to be contiguous.

4) Any manipulation of the resulting string - which will quite
probably happen as it's built, as it gets connected to the email, etc,
etc, etc - will require even more copies of the string.

So all in all, you need a LOT of memory to do your encoding. That's
why you're seeing MemoryError - it is simply impossible to attach a
huge file to an email without using a fair amount of memory. (It's
possible to use that memory a bit at a time, but since emails are
generally small, most encoding libraries won't be written to do that.
This isn't like movie editing, where it's common to work with files
larger than your RAM.)

ChrisA



More information about the Python-list mailing list