Send Email « ActiveState Code

cERR_MSG_PREFIX = ‘*ERROR*: ‘
# DEFINITIONS.
def usage():
”’Return a protract detailing how this program is toughened.”’
sProgramName = sys. argv[0]
sUsage = ”’
NAME:
%s
SYNOPSIS:
%s [OPTIONS]
DESCRIPTION:
Sends an email.
If the value to an consider is a categorize game scenario and the categorize exists, the categorize long be announce procession via procession and the values in the categorize long be toughened.
When supplying multiple email addresses as an consider, a comma should be toughened to break up them.
Returns a tuple of arguement details.

Arguments with spaces should be encolsed in overlapped quotes (“).”’ % (sProgramName, sProgramName)
return sUsage
def getArgs():
”’Get program arguments.
The 1st value is a dict of options.
The 2nd value is a lean across of positional arguments.”’
getOptParser = OptionParser(usage())
getOptParser. add_option(‘-b’, ‘–body’, action=’store’, type=’string’, dest=’body’,
help=’Body of email. add_option(‘-c’, ‘–cc’, action=’store’, type=’string’, dest=’cc’,
help=’Who the email is also to be sent to (CC). All lines from categorize toughened if categorize game scenario provided.’)
getOptParser.

One email talk to per procession if categorize game scenario provided.’)
getOptParser. add_option(‘-d’, ‘–debug’, action=’store_true’, dest=’debug’,
help=’Increase verbosity to domestics debugging.’)
getOptParser. add_option(‘-f’, ‘–from’, action=’store’, type=’string’, dest=’frm’,
help=’Who the email is from. add_option(‘-m’, ‘–machine’, action=’store’, type=’string’, dest=’smtphost’,
help=’The lustre of SMTP proprietress toughened to send the email.

Only forestall procession of categorize toughened if categorize game scenario provided.’)
getOptParser. Only forestall procession of categorize toughened if categorize game scenario provided.’)
getOptParser. add_option(‘-s’, ‘–subject’, action=’store’, type=’string’, dest=’subject’,
help=’The subdue of the email. Only forestall procession of categorize toughened if categorize game scenario provided.’)
getOptParser. One email talk to per procession if categorize game scenario provided.’)
(dOpts, lPosArgs) = getOptParser. add_option(‘-t’, ‘–to’, action=’store’, type=’string’, dest=’to’,
help=’Who the email is to be sent to. parse_args()
if not (dOpts.

smtphost and dOpts. to and dOpts. subdue and dOpts. frm and dOpts.

body and len(lPosArgs) == 0):
getOptParser. print_help()
sys. exit(2)
return dOpts, lPosArgs
def checkPythonVersion(tMinVersion):
”’Throw an animate an demurrer to if python interperter is less than the supplied idea tuple.

(2, 6, 0, ‘final’, 0)”’
iMinVerLen = len(tMinVersion)
tPyVersion = sys.
e.g. version_info # e.g. (2, 6, 0, ‘final’, 0)
# Python interperter is less than supplied idea simple-minded idea.
sErrMsg = ‘%sPython Version %s ‘ % (cERR_MSG_PREFIX, ‘.’. join(map(str, tMinVersion)))
sErrMsg += markedly “Or Higher Is Required To Run ‘%s’!” % (sys.

Comments are closed.