[Tutor] smtoplib script appears bogus

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 11 Dec 2001 23:38:41 -0800 (PST)


On Tue, 11 Dec 2001, Kirk Bailey wrote:

> This thing don't work. Beats me why, I copied it from the on line docs
> for the language, but there ya go.

Hi Kirk,

Can you be more specific about "don't work"?  I don't mean to be flippant
or unserious in asking this.  When asking for help on buggy code, it's
very important to say what the bug is --- error messages are always a good
thing to mention.  This helps reduce our chasing after the wind.


The only wild guess I can make is that to check that your program's
indentation begins at the very left margin.  The code that you quoted
suggests that you've already indented your code by one level, which Python
thinks of as a SyntaxError --- at least at the beginning, code needs to
start of with zero indentation.

Good luck to you.

> -----------------select aged bits---------------
>      import smtplib
>      import string
> 
>      def prompt(prompt):
>          return raw_input(prompt).strip()
> 
>      fromaddr = prompt("From: ")
>      toaddrs  = prompt("To: ").split()
>      print "Enter message, end with ^D:"
> 
>      # Add the From: and To: headers at the start!
>      msg = ("From: %s\r\nTo: %s\r\n\r\n"
>             % (fromaddr, string.join(toaddrs, ", ")))	# probably word
> wrapped.
>      while 1:						# when all on one line, it still don't work right.
>          try:
>              line = raw_input()
>          except EOFError:
>              break
>          if not line:
>              break
>          msg = msg + line
> 
>      print "Message length is " + `len(msg)`
> 
>      server = smtplib.SMTP('localhost')
>      server.set_debuglevel(1)
>      server.sendmail(fromaddr, toaddrs, msg)
>      server.quit()
> ------------------------------------------------------