In the previous post I mentioned a python script I was using with curl to send me a SMS message. Its a pretty quick and dirty one, but here is the script I use. Since these are quick messages meant for my phone - I don’t do much with the body. And I just use this with a GET style URL, although the python cgi lib could just as easily handle a POST. So I call it like this:
http://www.domain.net/cgi-bin/sendmemail.py?to=number@txt.att.net&subject=printing_done
I use this via curl in other scripts as a sort of notification system.
#! /usr/bin/env python
import cgi,cgitb
cgitb.enable()
# Required header that tells the browser how to render the text.
print "Content-Type: text/plain\n\n"
# Print a simple message to the display window.
from email.MIMEText import MIMEText
import smtplib,sys
The_Form = cgi.FieldStorage()
body='''blank
'''
msg = MIMEText(body)
mfrom = "email@example.com"
to = TheForm['to'].value
msg['From'] = mfrom
msg['To'] = to
msg['Subject'] = TheForm['subject'].value
server = smtplib.SMTP("smtp.gmail.com",587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(<smtp login>,<smtp password>)
server.sendmail(mfrom,[to],msg.as_string())
server.quit
print 'sent'
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment