It’s a nifty little trick that can come in handy. In my case, I use it to notify me if my webserver suddenly becomes unavailable for some reason. It uses the fact that most cell phones can be texted via email by using a certain adress, such as cell#@provider.net. The code I use:

def send_text(str):

HOST = "smtp.gmail.com"

SUBJECT = "Server offline!"
TO = "xxxxxxxxxx@txt.att.net"

FROM = "python@mydomain.com"

text = str
BODY = string.join(("From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT, "", text), "\r\n")

s = smtplib.SMTP('smtp.gmail.com',587)

s.set_debuglevel(1)

s.ehlo()

s.starttls()

s.login("username@gmail.com", "mypassword")

s.sendmail(FROM, [TO], BODY)

s.quit()

Leave a Reply

Your email address will not be published. Required fields are marked *