Friday, June 29, 2012

Python script send email using smtplib

#!/usr/bin/python

import smtplib

SERVER = "mail.example.com"

FROM = "noreply@example.com"
TO = ["User@example.com"]
SUBJECT = "Hello! I am Python"

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






# You can buy me a beer.

1 comment: