I have class to send emails. I'm trying to send an attachment of a zip file that is around 157 mb but I'M getting a memory error. When i send other smaller zip files the program works fine. Does anyone knows how to handle this issue so i can can send attachment similar to the ones that is causing the problem?
class Sender:
#constructor
def __init__(self,filename):
self.filename = filename
#functions
def message(self):
fromaddr = "myaddress@gm.com"
toaddr = ["address"]
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = ",".join(toaddr)
msg['Subject'] = "New Base Year"
# This is the binary part(The Attachment):
part = MIMEApplication(open('t:\\base_year_06_06_2014.zip',"rb").read())
part.add_header('Content-Disposition', 'attachment', filename='srping2013.zip')
msg.attach(part)
body = "Hello,"
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('c11', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("myaddress@gm.com", "password")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
return "Message Sent"
And this is the error i get when trying to send the zip file
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.1\Lib\site- packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "T:\Python scripts\scripts\test\zipper.py", line 58, in <module>
success = send_email.message()
File "T:\Python scripts\scripts\test\zipper.py", line 36, in message
text = msg.as_string()
File "C:\Python27\ArcGIS10.1\lib\email\message.py", line 137, in as_string
g.flatten(self, unixfrom=unixfrom)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 83, in flatten
self._write(msg)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 108, in _write
self._dispatch(msg)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 134, in _dispatch
meth(msg)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 203, in _handle_multipart
g.flatten(part, unixfrom=False)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 83, in flatten
self._write(msg)
File "C:\Python27\ArcGIS10.1\lib\email\generator.py", line 118, in _write
self._fp.write(sfp.getvalue())
MemoryError: out of memory