source: branches/testScripts/NBemail.py @ 624

Last change on this file since 624 was 622, checked in by kmartin, 12 years ago

upadte NBUserConfig.py script for Kipp paramaters

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5from socket import gethostname
6import smtplib
7
8import NBuserConfig
9import NBprojectConfig
10import NBlogMessages
11
12#------------------------------------------------------------------------
13#
14# This file contains the functions that deal with email
15#
16#------------------------------------------------------------------------
17
18#------------------------------------------------------------------------
19# Send email typically about an error.
20#  project: coin project name
21#  cmd: command being exucuted. perhaps: "svn update", "./configure",
22#       "make".
23#  cmdMsgs: the messages generated by cmd.  This will typically contain
24#       errors issued by cmd.
25#------------------------------------------------------------------------
26def sendCmdMsgs(project,cmdMsgs,cmd):
27  curDir = os.getcwd()
28 
29  toAddrs = [unscrambleAddress(NBuserConfig.MY_EMAIL_ADDR)]
30  if NBprojectConfig.PROJECT_EMAIL_ADDRS.has_key(project) \
31     and \
32     NBuserConfig.SEND_MAIL_TO_PROJECT_MANAGER:
33    scrambledEmailAddress=NBprojectConfig.PROJECT_EMAIL_ADDRS[project]
34    unscrambledEmailAddress=unscrambleAddress(scrambledEmailAddress)
35    toAddrs.append(unscrambledEmailAddress)
36
37  subject = project + " problem when running '" + cmd +"'"
38
39  emailMsg  = "'" + cmd + "' from directory " + curDir + " failed.\n\n"
40
41  emailMsg += "Operating System: "+sys.platform+" "+os.name+"\n"
42  emailMsg += "Host name: "+gethostname()+"\n\n"
43
44  emailMsg += "'" + cmd + "' messages are:\n" 
45  emailMsg += cmdMsgs
46  send(toAddrs,subject,emailMsg)
47  NBlogMessages.writeMessage( "  email sent regarding "+project+" running '"+cmd+"'" )
48
49#------------------------------------------------------------------------
50# Send email
51#------------------------------------------------------------------------
52def send(toAddrs,subject,message):
53
54  sender = unscrambleAddress(NBuserConfig.SENDER_EMAIL_ADDR) 
55  msgWHeader = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
56       % (sender, ", ".join(toAddrs), subject))
57  msgWHeader += message
58 
59  # Get smpt server password
60  if os.path.isfile(NBuserConfig.SMTP_PASSWORD_FILENAME) :
61    pwFilePtr = open(NBuserConfig.SMTP_PASSWORD_FILENAME,'r')
62    smtppass  = pwFilePtr.read().strip()
63    #print smtppass
64    pwFilePtr.close()
65  else :
66    NBlogMessages.writeMessage( "Failure reading pwFileName=" + NBuserConfig.SMTP_PASSWORD_FILENAME )
67    sys.exit(1)
68   
69  session = smtplib.SMTP(NBuserConfig.SMTP_SERVER_NAME,NBuserConfig.SMTP_SERVER_PORT)
70  #session.set_debuglevel(1)
71  if NBuserConfig.SMTP_SSL_SERVER==1 :
72    session.ehlo('x')
73    session.starttls()
74    session.ehlo('x') 
75  session.login(unscrambleAddress(NBuserConfig.SMTP_USER_NAME),smtppass)
76
77  rc = session.sendmail(sender,toAddrs,msgWHeader)
78  if rc!={} :
79    NBlogMessages.writeMessage( 'session.sendmail rc='  )
80    NBlogMessages.writeMessage( rc )
81  session.quit()
82
83#------------------------------------------------------------------------
84# Decrypt email address
85#------------------------------------------------------------------------
86def unscrambleAddress( scrambledEmailAddress ) :
87  retVal = scrambledEmailAddress
88  retVal = retVal.replace(' _AT_ ','@')
89  retVal = retVal.replace(' _DOT_ ','.')
90  return retVal
91
Note: See TracBrowser for help on using the repository browser.