How to send an email with GMail in Python from Windows

gordyt gordyt at
Thu Mar 12 15:46:03 CET 2009

Howdy Avinash,

Here is a simple example for you.

from smtplib import SMTP
HOST = ""
PORT = 587
ACCOUNT = ""        # put your gmail email account here
PASSWORD = ""       # put your gmail email password here

def send_email(to_addrs, subject, msg):
    server = SMTP(HOST,PORT)
    server.set_debuglevel(1)    # you don't need this (comment out to
avoid debug messages)
    server.login(ACCOUNT, PASSWORD)
    server.sendmail(ACCOUNT, to_addrs,
        """From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s\r\n.\r\n""" % (
            ACCOUNT, ",".join(to_addrs), subject, msg

if __name__ == "__main__":
    send_email( ['somewhat at'], 'this is just a test',
        "hello world!" )


More information about the Python-list mailing list