[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] [Pygame] Sending E-Mail Through Python
- To: pygame-users@xxxxxxxx
- Subject: [pygame] [Pygame] Sending E-Mail Through Python
- From: Kris Schnee <kschnee@xxxxxxxxxx>
- Date: Sun, 06 Feb 2005 23:57:41 -0500
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sun, 06 Feb 2005 23:58:17 -0500
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)
Any idea why the e-mail code provided in Python doesn't work for me?
Running the function below gives me the error: "SMTPServerDisconnected:
Connection unexpectedly closed." I think the problem is with the server,
which in the example code just gives "localhost." Changing that to
"www.xepher.net," my domain name, just hangs the program.
Kris
## e-mail.py
## Mostly copied from Python docs (www.python.org).
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.MIMEText import MIMEText
ONLINE = True
def SendEMail(content, whofrom, to, subject=""):
"""Send an e-mail."""
if not ONLINE:
return
# Create a text/plain message
msg = MIMEText( content )
msg['Subject'] = subject
msg['From'] = whofrom
msg['To'] = to
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP("localhost")
s.connect()
s.sendmail(whofrom, [to], msg.as_string())
s.close()