Send an email using python script

Posted by nimmyliji on Stack Overflow See other posts from Stack Overflow or by nimmyliji
Published on 2010-03-20T06:13:18Z Indexed on 2010/03/20 6:21 UTC
Read the original article Hit count: 512

Filed under:
|

Hi, Today I needed to send email from a Python script. As always I searched Google and found the following script that fits to my need.

import smtplib

SERVER = "localhost"

FROM = "[email protected]"
TO = ["[email protected]"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()

But when I tried to run the program, I got the following error message:

Traceback (most recent call last):
  File "C:/Python26/email.py", line 1, in <module>
    import smtplib
  File "C:\Python26\lib\smtplib.py", line 46, in <module>
    import email.utils
  File "C:/Python26/email.py", line 24, in <module>
    server = smtplib.SMTP(SERVER)
AttributeError: 'module' object has no attribute 'SMTP'

How can i solve this problem? Any one can help me?

Thanks in advance, Nimmy.

© Stack Overflow or respective owner

Related posts about python

Related posts about email