Skip to content

Instantly share code, notes, and snippets.

@prehistoricpenguin
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save prehistoricpenguin/0676a903f66e9db047f8 to your computer and use it in GitHub Desktop.

Select an option

Save prehistoricpenguin/0676a903f66e9db047f8 to your computer and use it in GitHub Desktop.
import win32com.client as win32
import time
import sys
import os
import shutil
def sendonemail(addr = "", attach = "", subject = ""):
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = addr
mail.Subject = subject
mail.body = "A mail aimed to send large file"
if not os.path.exists(attach):
print "file ", attach, " don't existed"
return
mail.Attachments.Add(attach)
mail.send
def sendbymail(addr = "", fullname = ""):
if (os.path.exists(fullname) is False):
print "file ", fullname, " not found"
return
root, ext = os.path.splitext(fullname)
head, tail = os.path.split(root)
tmpdir = "tmpdir" + str(os.getpid())
tmpdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), tmpdir)
tmpfilehead = os.path.join(tmpdir, tail)
os.mkdir(tmpdir)
maxsize = 19
cmdstr = "rar a -m5 -v" + str(maxsize) + "m " + tmpfilehead + \
" " + fullname
#print "cmd :", cmdstr
# call winrar to compress the file
os.system(cmdstr)
# send each volumns
volumnnum = 1
for directory, dirnames, filenames in os.walk(tmpdir):
for fname in filenames:
print "sending volumn ", volumnnum, "..."
volumnnum += 1
sendonemail(addr, os.path.join(tmpdir, fname))
time.sleep(1)
print "Done !"
# delet temp directory
shutil.rmtree(tmpdir)
if __name__ == "__main__":
if len(sys.argv) < 3:
print "usage :sendbymail $address $filename"
else:
sendbymail(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment