[Tutor] smtplib problems ?
dave
pythontut at pusspaws.net
Mon Nov 21 20:59:33 CET 2005
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 = 'XXXX at chubb.co.uk'
email_addr2 = 'XXXX at pusspaws.net'
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
{'XXXX at chubb.co.uk': (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
More information about the Tutor
mailing list