intresting buried treasure in the on line reference manual
Kirk Bailey
deliberatus at my995internet.com
Sun Dec 9 01:21:22 EST 2001
Sending a message in python to the mail MTA
I also found this in the refernece, very helpful, eccept for 2 things- a
line of gibberish, and there is a bug on line 14.
Relevant page: http://www.python.org/doc/current/lib/SMTP-example.html
1 import smtplib
2 import string
3
4 def prompt(prompt):
5 return raw_input(prompt).strip()
6
7 fromaddr = prompt("From: ")
8 toaddrs = prompt("To: ").split()
9 print "Enter message, end with ^D:"
10
11 # Add the From: and To: headers at the start!
12 msg = ("From: %s\r\nTo: %s\r\n\r\n"
13 % (fromaddr, string.join(toaddrs, ", "))) # <-- I suspect
this is a linewrap error, it does not bomb
14 while 1: # <-- this line screws everything up! # if I place
it all on one line.
15 try: # the test is
APPARENTLY to create an endless loop with 2
16 line = raw_input() # hard coded exit
conditions manually built in. But my python hates it.
17 except EOFError:
18 break
19 if not line:
20 break
21 msg = msg + line
22
23 print "Message length is " + `len(msg)`
24
25 server = smtplib.SMTP('localhost')
26 server.set_debuglevel(1)
27 server.sendmail(fromaddr, toaddrs, msg)
28 server.quit()
29
30
--
Respectfully,
-Kirk D Bailey (C)2001
Addme! icq #27840081
end
Within the sweep of his sword, Each man is an Ubar.
http://www.howlermonkey.net/
http://www.sacredelectron.org/
More information about the Python-list
mailing list