Skip to content

Instantly share code, notes, and snippets.

@entrity
Created June 9, 2021 22:47
Show Gist options
  • Save entrity/72e40e5267fe19814c28a58ebe0ebdba to your computer and use it in GitHub Desktop.
Save entrity/72e40e5267fe19814c28a58ebe0ebdba to your computer and use it in GitHub Desktop.
Python CGI mailer
import smtplib
import cgi
FROM_ADDR = ''
TO_ADDR = ''
USERNAME = FROM_ADDR
PASSWORD = ''
LOG_DIR = '.'
print 'foo'
def send_email(message):
server = smtplib.SMTP(SMTP_HOST, 587, DOMAIN)
server.ehlo()
server.starttls()
server.ehlo()
server.login(USERNAME, PASSWORD)
server.sendmail(FROM_ADDR, TO_ADDR, message)
server.quit()
def build_message():
return "From: %s\r\nSubject: From Form\r\nTo: %s\r\n\r\nbody" % (FROM_ADDR, TO_ADDR)
def get_cgi():
return cgi.FieldStorage()
send_email(get_cgi())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment