I am trying to write a little python script to send me an email to alert me that a troublesome ArcServer service has stopped on a windows server. I've done stuff like this in perl, but I thought I should do this in python because the server already has python 2.5 installed and I need to learn more python.I found the WService Class http://code.activestate.com/recipes/1158...-services/ right away and it worked great. In just a few lines. I could write something that would stay running until a service stopped, then I can branch to sending the email:from sys import exit
import time, win32api, win32con, win32service
wa, wc, ws = win32api, win32con, win32service
import WService
iis = WService.WService("IIS Admin")
iis.fetchstatus("stopped")
print "IIS Stopped"
class WService:
**
**
but the email part has given me some problems, making me realize I don't know much about python basics.I've been trying to test with the simple text message example found around the net: http://docs.python.org/library/email-examples.html# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open('textfile.txt', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()
me == "*****@yakama.com"
you == "*****@yakama.com"
msg['Subject'] = 'The contents of %s' % 'textfile.txt'
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP()
s.connect()
s.sendmail(me, [you], msg.as_string())
s.close()
But had some trouble figuring out where all my substitutions would go and what the syntax is supposed to be, like in quotes or not. But now I'm hitting an error at line 9: fp = open('textfile.txt', 'rb')
IOError: [Errno 2] No such file or directory: 'textfile.txt'
even though I created a textfile.txt in the same directory as the script. Why can't I get open to work? Do I need to set a path?I looked at the Google App Engine python email but apparently it didn't install for me correctly. After running the msi, from google.appengine.api import mail
in an interactive window can't find the module.