I have the following email routine in a program that's running against ArcGIS10:
def eMail(num, countFile):
# Open the completed output file for reading.
if (num == 1):
outputR = open(countFile, "r")
msg = MIMEText(outputR.read())
msg = MIMEText("TEST -- System Generated Message: There were no non-LR Layers updated in Prod 5171")
mailRecipients = 
for name in recipients:
name += "@loudoun.gov"
COMMASPACE = ', '
msg['Subject'] = 'NonLR Update Prod2Browse : Success'
msg['From'] = 'email@example.com'
msg['To'] = COMMASPACE.join(mailRecipients)
## Send the message via our own SMTP server, but don't include the envelope header.
s = smtplib.SMTP('smtprelay.prod.loudoun.local', '25')
s.sendmail('firstname.lastname@example.org', mailRecipients, msg.as_string())
del msg, s
The recipients variable is defined as follows:
recepients = ["Charles.Shore","Saraswathi.Emani"]
and the error handling class is:
def __init__(self, prev, next, msg):
self.prev = prev
self.next = next
self.msg = msg
errF = open(errFile, "w")
errF.write(str(CURRTIME) + '\n\n')
If there are data layers in a specified text file, then num = 1 and the first message (showing the record counts) is defined. Otherwise, num = 2 and the second message is defined.
The last few times I tested this (several weeks ago), this all worked fine. However, now I'm having two problems:
1) In the finally clause, I'm told I can't delete 'msg' and 's' before they're defined.
2) The ConnErr class is looking for 4 arguments. I understand that 'prev' and 'next' refer to transition states, but I haven't found any explanation in the literature as to what those states should be. Should the 3 arguments (excluding 'self') be strings?
Finally, why should this code work fine one week, then crash several weeks later?