# Email syntax for python 3
# Stolen and modified from http://stackoverflow.com/questions/10147455/trying-to-send-email-gmail-as-mail-provider-using-python
#
def send_email(input):
import smtplib
gmail_user = "jugglingdatabase1@gmail.com"
gmail_pwd = "TheFrontBottoms"
FROM = 'jugglingdatabase1@gmail.com'
#TO = ['chm30@humboldt.edu','jic74@humboldt.edu','bmd269@humboldt.edu'] #must be a list
TO = ['James.Graham@humboldt.edu'] #Test email
SUBJECT = "Database Update for CircusMyAdventure"
TEXT = input
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
#server.quit()
server.close()
print("successfully sent the mail")
except:
print("failed to send mail")
# Sanitizing HTML inputs
# Removes 's, "s, <s and >s and replaces with HTML escape codes
#
def escape(htmlstring):
escapes = {'\"': '"',
'\'': ''',
'<': '<',
'>': '>'}
# This is done first to prevent escaping other escapes.
htmlstring = htmlstring.replace('&', '&')
for seq, esc in escapes.iteritems():
htmlstring = htmlstring.replace(seq, esc)
return htmlstring
send_email("Hey, I'm Connor Morison, and I'm sending this to you through Python. ")
© Copyright 2018 HSU - All rights reserved.