Skip to content

Instantly share code, notes, and snippets.

@urbans
Created April 12, 2012 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urbans/2370734 to your computer and use it in GitHub Desktop.
Save urbans/2370734 to your computer and use it in GitHub Desktop.
Server status via email (python)
import smtplib
import commands
# Email details
from_address = 'Status reporter<my.status.reporter@gmail.com>'
to_address = 'recipient@gmail.com'
message_subject = "My server daily report"
# Credentials
username = 'my.status.reporter@gmail.com'
password = '*******'
# Assemble message
msg_body = commands.getoutput('df -h') + "\r\n\r\n" + "Uptime: " + commands.getoutput('uptime') + "\r\nDate: " + commands.getoutput("date") + "\r\n\r\n"
message = "From: %s\r\n" % from_address + "To: %s\r\n" % to_address + "Subject: %s\r\n" % message_subject + "\r\n" + msg_body
# Send mail
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username,password)
server.sendmail(from_address, to_address, message)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment