using smtp sent large file upto 60MB

Discussion in 'Python' started by moonhkt, Dec 4, 2012.

  1. moonhkt

    moonhkt Guest

    Hi All

    How to using python send file uptp 60MB ?


    s = smtplib.SMTP("localhost")
    #~~ s.set_debuglevel(1)
    s.sendmail(from_addr, to_addr,m.as_string())
    s.quit


    For 13MB file have below error
    s.sendmail(from_addr, to_addr,m.as_string())
    File "/opt/freeware/lib/python2.6/email/message.py", line 135, in
    as_string
    g.flatten(self, unixfrom=unixfrom)
    File "/opt/freeware/lib/python2.6/email/generator.py", line 84, in
    flatten
    self._write(msg)
    File "/opt/freeware/lib/python2.6/email/generator.py", line 119, in
    _write
    self._fp.write(sfp.getvalue())
    MemoryError: out of memory
    moonhkt, Dec 4, 2012
    #1
    1. Advertising

  2. On Tue, Dec 4, 2012 at 7:15 PM, moonhkt <> wrote:
    > How to using python send file uptp 60MB ?


    Step one: Don't. SMTP is almost never the best choice for sending huge
    files around.

    There are plenty of other ways to share files; send an email with
    instructions on how to access the file, rather than attaching the
    file. For general consumption, the easiest way is usually to include a
    URL for HTTP download. If it's something internal, you might want to
    put the file on a shared-access FTP server or file share.

    ChrisA
    Chris Angelico, Dec 4, 2012
    #2
    1. Advertising

  3. moonhkt

    moonhkt Guest

    On Dec 4, 6:07 pm, Chris Angelico <> wrote:
    > On Tue, Dec 4, 2012 at 7:15 PM, moonhkt <> wrote:
    > > How to using python send file uptp 60MB ?

    >
    > Step one: Don't. SMTP is almost never the best choice for sending huge
    > files around.
    >
    > There are plenty of other ways to share files; send an email with
    > instructions on how to access the file, rather than attaching the
    > file. For general consumption, the easiest way is usually to include a
    > URL for HTTP download. If it's something internal, you might want to
    > put the file on a shared-access FTP server or file share.
    >
    > ChrisA


    Thank for suggestion. The next task will be ftp to user folder. But
    first tasks is how to using python send huge files.
    moonhkt, Dec 4, 2012
    #3
  4. moonhkt

    Laszlo Nagy Guest


    > Thank for suggestion. The next task will be ftp to user folder. But
    > first tasks is how to using python send huge files.

    Most SMTP servers are configured not to accept attachments bigger than
    10 or 15MB. In general, you should never send emails with >5MB
    attachments. Not because it is not possible, but because it is
    unreliable, and the solution is never in your hand. The solution depends
    on the SMTP server configuration, and in most cases you don't have
    access to the computers holding the final destination of the emails.

    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.
    Laszlo Nagy, Dec 4, 2012
    #4
  5. On Wed, Dec 5, 2012 at 2:41 AM, Laszlo Nagy <> 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
    Chris Angelico, Dec 4, 2012
    #5
  6. moonhkt

    moonhkt Guest

    On 12月5æ—¥, 上åˆ4時54分, Chris Angelico <> wrote:
    > On Wed, Dec 5, 2012 at 2:41 AM, Laszlo Nagy <> wrote:
    > > If you still don't want to accept this suggestion, then go ahead! Writea
    > > 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


    Thank for your suggestion.

    Machine : AIX
    Python version : 2.6.2

    I am prepare change UNIX script to Python. smtp and ftp are my first
    tasks.

    But, when using standard unix command mail and uuencode without this
    issue.

    Our SMTP can send file more than 60MB. But our notes server can
    configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.

    In UNIX, by below command send smtp mail.
    uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME

    moonhkt
    moonhkt, Dec 5, 2012
    #6
  7. On Wed, Dec 5, 2012 at 11:54 AM, moonhkt <> wrote:
    > I am prepare change UNIX script to Python. smtp and ftp are my first
    > tasks.
    >
    > But, when using standard unix command mail and uuencode without this
    > issue.
    >
    > Our SMTP can send file more than 60MB. But our notes server can
    > configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.
    >
    > In UNIX, by below command send smtp mail.
    > uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME


    Yes, and it is possible to send that much content via SMTP. It just
    isn't something that library authors are going to be overly concerned
    about. You may need to jump through a few extra hoops, or maybe just
    throw more RAM at the computer (possibly switching to a 64-bit build
    of Python if you aren't already using one). However, I would *still*
    recommend using a different transport for such large files.

    ChrisA
    Chris Angelico, Dec 5, 2012
    #7
  8. moonhkt

    moonhkt Guest

    On 12月5æ—¥, 下åˆ1時34分, Chris Angelico <> wrote:
    > On Wed, Dec 5, 2012 at 11:54 AM, moonhkt <> wrote:
    > > I am prepare change UNIX script to Python. smtp and ftp are my first
    > > tasks.

    >
    > > But, when using standard unix command mail and uuencode without this
    > > issue.

    >
    > > Our SMTP can send file more than 60MB. But our notes server can
    > > configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.

    >
    > > In UNIX, by below command send  smtp mail.
    > > uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME

    >
    > Yes, and it is possible to send that much content via SMTP. It just
    > isn't something that library authors are going to be overly concerned
    > about. You may need to jump through a few extra hoops, or maybe just
    > throw more RAM at the computer (possibly switching to a 64-bit build
    > of Python if you aren't already using one). However, I would *still*
    > recommend using a different transport for such large files.
    >
    > ChrisA


    Thank a lot. We still using Python version : 2.6.2 on AIX 5.3
    moonhkt, Dec 5, 2012
    #8
  9. On 12/04/2012 05:54 PM, moonhkt wrote:
    > Our SMTP can send file more than 60MB. But our notes server can
    > configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.
    >
    > In UNIX, by below command send smtp mail.
    > uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME


    Just continue to use this set of commands. You can use the subprocess
    module to interact with these programs.
    Michael Torrie, Dec 5, 2012
    #9
  10. moonhkt

    moonhkt Guest

    On 12月5æ—¥, 下åˆ11時01分, MichaelTorrie <> wrote:
    > On 12/04/2012 05:54 PM, moonhkt wrote:
    >
    > > Our SMTP can send file more than 60MB. But our notes server can
    > > configured 100MB,30MB or 10MB. My notes Mail box can receive 100MB.

    >
    > > In UNIX, by below command send  smtp mail.
    > > uuencode $xfn $xfn | mail -s "$SUBJECT" $NAME

    >
    > Just continue to use this set of commands.  You can use the subprocess
    > module to interact with these programs.


    OK. Will try using subprocess.
    moonhkt, Dec 10, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curt_C [MVP]
    Replies:
    5
    Views:
    350
    Karim
    May 19, 2004
  2. Replies:
    34
    Views:
    13,164
  3. Replies:
    3
    Views:
    1,045
    Roedy Green
    Jan 24, 2006
  4. Alex Hunsley
    Replies:
    4
    Views:
    3,390
    Tim Williams (gmail)
    Jun 29, 2004
  5. William Connery
    Replies:
    0
    Views:
    255
    William Connery
    Dec 5, 2006
Loading...

Share This Page