-#!/usr/bin/python
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Chromite email utility functions."""
+from __future__ import print_function
+
import cStringIO
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
DEFAULT_SMTP_SERVER = 'localhost'
+def _SendEmailHelper(smtp_server, sender, email_recipients, msg):
+ """Send an email.
+
+ Args:
+ smtp_server: The server with which to send the message.
+ sender: The from address of the sender of the email.
+ email_recipients: The recipients of the message.
+ msg: A MIMEMultipart() object containing the body of the message.
+ """
+ smtp_client = smtplib.SMTP(smtp_server)
+ smtp_client.sendmail(sender, email_recipients, msg.as_string())
+ smtp_client.quit()
+
+
def SendEmail(subject, recipients, smtp_server=None, message='',
attachment=None, extra_fields=None):
"""Send an e-mail job notification with the given message in the body.
part.add_header('Content-Disposition', 'attachment', filename='logs.txt.gz')
msg.attach(part)
- smtp_client = smtplib.SMTP(smtp_server)
- smtp_client.sendmail(sender, email_recipients, msg.as_string())
- smtp_client.quit()
+ _SendEmailHelper(smtp_server, sender, email_recipients, msg)
def SendEmailLog(subject, recipients, smtp_server=None, message='',
attachment = ''.join(log)
SendEmail(subject, recipients, smtp_server, message=message,
- attachment=attachment, extra_fields=extra_fields)
\ No newline at end of file
+ attachment=attachment, extra_fields=extra_fields)