still a newbie in Python world so first question from me, hope somebody can help. So here's some simple code that lists the directories in a path and I'd like to send the output to an email. The email setup works as it'll mail the "TEXT" to me, but I have really struggled with trying to capture the stdout from the print function.
Thanks
for root, dirs, files in os.walk(path):
for curDir in dirs:
fulldir = os.path.join(root, curDir)
print '\nThis dir : %s' % (fulldir)
### Email setup
SERVER = "myserver"
PORT = "25"
FROM = "me@me.com"
TO = ["me@me.com"]
SUBJECT = "Some dirs"
TEXT = "The print loop from above please"
# Prepare actual message
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
### Send the message
server = smtplib.SMTP(SERVER, PORT)
server.sendmail(FROM, TO, message)
server.quit()