[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] [Pygame] Sending E-Mail Through Python



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()