Skip to content

Instantly share code, notes, and snippets.

@jldupont
Created September 15, 2010 21:16
Show Gist options
  • Save jldupont/581501 to your computer and use it in GitHub Desktop.
Save jldupont/581501 to your computer and use it in GitHub Desktop.
Sending mail to local user
"""
Sending local email
Created on 2010-09-15
@author: jldupont
"""
import smtplib
import getpass
SERVER = "localhost"
FROM = "somesender@localhost"
TO = ["%s@localhost" % getpass.getuser()]
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment