[tor-commits] [doctor/master] Sending email via our local mail application

atagar at torproject.org atagar at torproject.org
Mon Sep 16 18:45:14 UTC 2013


commit 54be0252197aa38dcda30415e1c25d6a08fe9f03
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Sep 16 11:49:32 2013 -0700

    Sending email via our local mail application
    
    The java version of doctor sends email via...
    
    cat out/status/all-warnings | mail -E -s 'Consensus issues' tor-consensus-health at lists.torproject.org
    
    Gonna give this a whirl for our python version on yatei...
---
 util.py |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/util.py b/util.py
index 4874327..32e795e 100644
--- a/util.py
+++ b/util.py
@@ -5,6 +5,7 @@ Module for issuing email notifications to me via gmail.
 import logging
 import os
 import smtplib
+import subprocess
 
 from email import Encoders
 from email.mime.multipart import MIMEMultipart
@@ -78,7 +79,26 @@ def log_stem_debugging(name):
   log.addHandler(handler)
 
 
-def send(subject, body_text = None, body_html = None, attachment = None, destination = TO_ADDRESS):
+def send(subject, body_text = None, destination = TO_ADDRESS):
+  """
+  Sends an email notification via the local mail application.
+
+  :param str subject: subject of the email
+  :param str body_text: plaintext body of the email
+  :param str destination: location to send the email to
+
+  :raises: **Exception** if the email fails to be sent
+  """
+
+  process = subprocess.Popen(['mail', '-E', '-s', subject, destination], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
+  stdout, stderr = process.communicate(body_text)
+  exit_code = process.poll()
+
+  if exit_code != 0:
+    raise ValueError("Unable to send email: %s" % stderr.strip())
+
+
+def send_via_gmail(subject, body_text = None, body_html = None, attachment = None, destination = TO_ADDRESS):
   """
   Sends an email notification via gmail.
 
@@ -86,6 +106,7 @@ def send(subject, body_text = None, body_html = None, attachment = None, destina
   :param str body_text: plaintext body of the email
   :param str body_html: html body of the email
   :param str attachment: path of a file to attach
+  :param str destination: location to send the email to
 
   :raises: **Exception** if the email fails to be sent
   """



More information about the tor-commits mailing list