Hi all,
I am not sure if this is a Python problem not not but here goes....
I wrote the following small script to email by boss 'email_addr' a rather
important reminder and also send a copy to myself 'email_addr2' several times
a day.
#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
from smtplib import SMTP
from time import sleep
import sys
email_SMTP = 'mail.pusspaws.net'
email_addr = '[EMAIL PROTECTED]'
email_addr2 = '[EMAIL PROTECTED]'
def email_remind():
for trys in xrange(10):
try:
mail_server = SMTP(email_SMTP)
# email the office with a full email
blog="""\n\nHi,\n\nHi,This is just a reminder, can you sort me out
a date for my re-grade exam as soon as possible.
I have tied an email script into my cron (time scheduling) daemon to remind
you an ever increasing number of times a day ;) - Got to love
Linux\n\nCheers\n\nDave"""
msg = ('Subject: Friendly reminder :)\r\nFrom: Dave Selby\r\nTo:
'+\
email_addr+'\r\n\r\n'+blog+'\r\n\r\n')
mail_server.sendmail('Friendly reminder :)', email_addr, msg)
mail_server.sendmail('Friendly reminder :)', email_addr2, msg)
mail_server.quit()
# If we get to here, all is well, drop out of the loop
break
except:
print 'Mailing error ... Re-trying ... '+str(trys+1)+' of 10\n'
sleep(300)
if trys==9:
raise 'Mail Failure\n'+str(sys.exc_type)+'\n'+str(sys.exc_value)
email_remind()
It does the job (regrade exam now booked :)) but It succeeds in sending emails
only about 50% of the time. The other 50% I get ...
Mailing error ... Re-trying ... 1 of 10
Mailing error ... Re-trying ... 2 of 10
Mailing error ... Re-trying ... 3 of 10
Mailing error ... Re-trying ... 4 of 10
Mailing error ... Re-trying ... 5 of 10
Mailing error ... Re-trying ... 6 of 10
Mailing error ... Re-trying ... 7 of 10
Mailing error ... Re-trying ... 8 of 10
Mailing error ... Re-trying ... 9 of 10
Mailing error ... Re-trying ... 10 of 10
Traceback (most recent call last):
File "/home/dave/my files/andrew_torture/email_remind.py", line 49, in ?
email_remind()
File "/home/dave/my files/andrew_torture/email_remind.py", line 43, in
email_remind
raise 'Mail Failure\n'+str(sys.exc_type)+'\n'+str(sys.exc_value)
Mail Failure
smtplib.SMTPRecipientsRefused
{'[EMAIL PROTECTED]': (553, "sorry, that domain isn't in my list of allowed
rcpthosts (#5.7.1)")}
I do not know if the is me not using the SMTP function correctly, I have
noticed the emails arrive and kmail cannot work out when they were sent, or
if the problem lies elsewear.
Any suggestions gratefully recieved
Cheers
Dave
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor