path = args.pathname
if path:
if path.is_dir():
# compress the folder before submitting
# compressed file is named by subject
compath = path.parent / (args.subject+".7z")
subprocess.run(["7z", "a", "-t7z", compath, path])
envelope.add_attachment(str(compath))
elif path.is_file():
envelope.add_attachment(str(path))
envelope.send(...)
print('The email is sent to ...')
if path.is_dir(): # delete the compressed file finally
os.remove(compath)
Following is a part of my command line tool