smtp
Hegedüs, Ervin
airween at gmail.com
Mon Aug 8 14:06:18 EDT 2011
hello,
>
> import smtplib
> def prompt(prompt):
> return raw_input(prompt).strip()
> fromaddr = prompt("From: ")toaddrs = prompt("To: ").split()print
> "Enter message, end with ^D (Unix) or ^Z (Windows):"
> # Add the From: and To: headers at the start!msg = ("From: %s\r\nTo: %s\r\n\r\n"
> % (fromaddr, ", ".join(toaddrs)))while 1:
> try:
> line = raw_input()
> except EOFError:
> break
> if not line:
> break
> msg = msg + line
> print "Message length is " + repr(len(msg))
> server = smtplib.SMTP('localhost')server.set_debuglevel(1)server.sendmail(fromaddr,
> toaddrs, msg)server.quit()
>
> and it returns -
> "TypeError" with no other information...
> It appears to be generated from the line
>
> msg = ("From: %s\r\nTo: %s\r\n\r\n"
> % (fromaddr, ", ".join(toaddrs)))
>
> But I'm not sure why...
after I copied it to a script, I've got this result:
From: airween at gmail.com
To: airween at index.hu
Enter message, end with ^D (Unix) or ^Z (Windows):
Teszt
Message length is 55
send: 'ehlo slave.myhost.hu\r\n'
reply: '250-ns2.myhost.hu\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 10240000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-STARTTLS\r\n'
reply: '250-AUTH PLAIN LOGIN\r\n'
reply: '250-AUTH=PLAIN LOGIN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: ns2.myhost.hu
PIPELINING
SIZE 10240000
VRFY
ETRN
STARTTLS
AUTH PLAIN LOGIN
AUTH=PLAIN LOGIN
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<airween at gmail.com> size=55\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<airween at index.hu>\r\n'
reply: '250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: 2.1.5 Ok
send: 'data\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
send: 'From: airween at gmail.com\r\nTo: airween at index.hu\r\n\r\nTeszt\r\n.\r\n'
reply: '250 2.0.0 Ok: queued as 643F144002\r\n'
reply: retcode (250); Msg: 2.0.0 Ok: queued as 643F144002
data: (250, '2.0.0 Ok: queued as 643F144002')
send: 'quit\r\n'
reply: '221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: 2.0.0 Bye
And there is that mail in my inbox...
Debian Lenny, Python 2.5.2
a.
More information about the Python-list
mailing list