smtplib problem for newbie

N

Noah Gift

Hi,

I am writing a few different scripts that need to send email
confirmation and I wanted to use smtplib instead of cheating and using
os.system('mail -s "foo"....) Some of the examples I have seen don't
seem to work for me. (Note, I am new to Python and probably doing
something stupid...thanks :) ) Here is one I grabbed
http://effbot.org/librarybook/smtplib.htm

import smtplib
import string, sys

HOST = "localhost"

FROM = "(e-mail address removed)"
TO = "(e-mail address removed)"

SUBJECT = "for your information!"

BODY = "next week: how to fling an otter"

body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], body)
server.quit()

If I change this to suit my needs it looks like this:

#!/usr/bin/python
import smtplib
import string, sys

HOST = "localhost"

FROM = "(e-mail address removed)"
TO = "(e-mail address removed)"

SUBJECT = "for your information!"

BODY = "next week: how to fling an otter"

body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], body)
server.quit()

When I run it I get this:

Traceback (most recent call last):
File "./3mail.py", line 2, in ?
import smtplib
File "/usr/lib64/python2.3/smtplib.py", line 49, in ?
from email.base64MIME import encode as encode_base64
File "/usr/lib64/python2.3/email/base64MIME.py", line 28, in ?
from email.Utils import fix_eols
File "/usr/lib64/python2.3/email/Utils.py", line 10, in ?
import random
File "/usr/lib64/python2.3/random.py", line 818, in ?
_inst = Random()
File "/usr/lib64/python2.3/random.py", line 87, in __init__
self.seed(x)
File "/usr/lib64/python2.3/random.py", line 100, in seed
a = long(time.time() * 256) # use fractional seconds
TypeError: 'module' object is not callable
 
J

Justin Azoff

Noah Gift wrote:
[snip]
a = long(time.time() * 256) # use fractional seconds
TypeError: 'module' object is not callable

Part of your program includes a file or directory that you called
'long'. You should not re-use names of built-ins in your programs..
they cause you to get errors like the above.

see:
Traceback (most recent call last):
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top