D
dccarson
Here is a snippet of code which does not send to all recipients.
However, it also does not inform me of this error. My suspicion is
that this only fails for users with longer usernames. The two I seem
to regularly fail on have 9 and 11 characters respectively. Most users
have names <= 8 characters.
domain = "myDomainHere.com"
admin = "d123456@%s" % domain
adminFull = "Full Name Here <%s>" % admin
def mailMsg(text, subject, sender, recipients):
# From: and To: headers at the start!
if not sender:
sender = adminFull
elif not sender.endswith(domain):
sender += ("@" + domain)
addresslist = []
for name in recipients:
if not name.endswith(domain):
name += ("@" + domain)
addresslist.append(name)
msg = "From: %s\r\nTo: %s\r\n" % (sender, ", ".join(addresslist))
msg += "Subject: %s\r\n\r\n" % subject
for line in text.split('\n'):
msg += "%s\r\n" % line.rstrip()
try:
server = smtplib.SMTP('localhost')
server.set_debuglevel(0)
failures = server.sendmail(sender, recipients, msg)
if len(failures):
safeMailMsg("%s\n\n%s" % (failures, msg),
"ttLadder: sent with failures", [admin])
server.quit()
except smtplib.SMTPSenderRefused, sndErr:
safeMailMsg("%s\n\n%s" % (sndErr, msg),
"ttLadder: sender refused", [admin])
except smtplib.SMTPRecipientsRefused, rcpErr:
safeMailMsg("%s\n\n%s" % (rcpErr, msg),
"ttLadder: recipients refused", [admin])
except Exception, xcp:
safeMailMsg("%s\n\n%s" % (xcp, msg),
"ttLadder: other exception", [admin])
return
The safeMailMsg() routine uses os.system("mail..."). It works but it
is not sending me any error in this case.
When I test by sending the same mail to myself (7 characters) and a
long name (11 characters), I receive the e-mail but the other user does
not. However, the header in the mail looks correct and if I do a
"Reply-all" it will happily send the mail to both of us.
Is this a known problem with older versions of smtplib? I'm using
Python 2.2.2.
Thanks,
David
However, it also does not inform me of this error. My suspicion is
that this only fails for users with longer usernames. The two I seem
to regularly fail on have 9 and 11 characters respectively. Most users
have names <= 8 characters.
domain = "myDomainHere.com"
admin = "d123456@%s" % domain
adminFull = "Full Name Here <%s>" % admin
def mailMsg(text, subject, sender, recipients):
# From: and To: headers at the start!
if not sender:
sender = adminFull
elif not sender.endswith(domain):
sender += ("@" + domain)
addresslist = []
for name in recipients:
if not name.endswith(domain):
name += ("@" + domain)
addresslist.append(name)
msg = "From: %s\r\nTo: %s\r\n" % (sender, ", ".join(addresslist))
msg += "Subject: %s\r\n\r\n" % subject
for line in text.split('\n'):
msg += "%s\r\n" % line.rstrip()
try:
server = smtplib.SMTP('localhost')
server.set_debuglevel(0)
failures = server.sendmail(sender, recipients, msg)
if len(failures):
safeMailMsg("%s\n\n%s" % (failures, msg),
"ttLadder: sent with failures", [admin])
server.quit()
except smtplib.SMTPSenderRefused, sndErr:
safeMailMsg("%s\n\n%s" % (sndErr, msg),
"ttLadder: sender refused", [admin])
except smtplib.SMTPRecipientsRefused, rcpErr:
safeMailMsg("%s\n\n%s" % (rcpErr, msg),
"ttLadder: recipients refused", [admin])
except Exception, xcp:
safeMailMsg("%s\n\n%s" % (xcp, msg),
"ttLadder: other exception", [admin])
return
The safeMailMsg() routine uses os.system("mail..."). It works but it
is not sending me any error in this case.
When I test by sending the same mail to myself (7 characters) and a
long name (11 characters), I receive the e-mail but the other user does
not. However, the header in the mail looks correct and if I do a
"Reply-all" it will happily send the mail to both of us.
Is this a known problem with older versions of smtplib? I'm using
Python 2.2.2.
Thanks,
David