Skip to content

Instantly share code, notes, and snippets.

@urbans urbans/send_mail.py
Created Apr 12, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.