Skip to content

Commit

Permalink
first go at using fabric to send the email
Browse files Browse the repository at this point in the history
  • Loading branch information
askedrelic committed May 20, 2012
1 parent ad39bbf commit 48cadcf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from fabric.api import task

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

import datetime
import os

import commands

username = os.environ['SENDGRID_USERNAME']
password = os.environ['SENDGRID_PASSWORD']
to_email = os.environ['CRON_EMAIL']

def send_email(email_msg):
print "Running cron at %s" % datetime.datetime.now()

msg = MIMEMultipart('alternative')
msg['Subject'] = "Comcast Bandwidth Usage"
msg['From'] = username
msg['To'] = to_email
msg.attach(MIMEText(email_msg, 'plain'))

s = smtplib.SMTP('smtp.sendgrid.net', 587)
s.login(username, password)
s.sendmail(username, to_email, msg.as_string())
s.quit()

@task
def send():
output = commands.getoutput('python comcastBandwidth.py')
send_email(output)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mechanize
fabric

0 comments on commit 48cadcf

Please sign in to comment.