00001
00002
00003
00004
00005
00006 """
00007 :py:class:`PSCalib.DCEmail` - class for Detector Calibration Store (DCS) project.
00008
00009 Usage::
00010
00011 # Import
00012 from PSCalib.DCEmail import send_text_email
00013
00014 # Send message via e-mail
00015 send_text_email(msg='Text message',\
00016 subject='Text subject',\
00017 email_from='do-not-reply@slac.stanford.edu',\
00018 email_to='do-not-send@slac.stanford.edu')
00019
00020 @see project modules
00021 * :py:class:`PSCalib.DCStore`
00022 * :py:class:`PSCalib.DCType`
00023 * :py:class:`PSCalib.DCRange`
00024 * :py:class:`PSCalib.DCVersion`
00025 * :py:class:`PSCalib.DCBase`
00026 * :py:class:`PSCalib.DCInterface`
00027 * :py:class:`PSCalib.DCUtils`
00028 * :py:class:`PSCalib.DCDetectorId`
00029 * :py:class:`PSCalib.DCConfigParameters`
00030 * :py:class:`PSCalib.DCFileName`
00031 * :py:class:`PSCalib.DCLogger`
00032 * :py:class:`PSCalib.DCMethods`
00033 * :py:class:`PSCalib.DCEmail`
00034
00035 This software was developed for the SIT project.
00036 If you use all or part of it, please give an appropriate acknowledgment.
00037
00038 @version $Id: DCEmail.py 12660 2016-09-27 00:33:40Z dubrovin@SLAC.STANFORD.EDU $
00039
00040 @author Mikhail S. Dubrovin
00041 """
00042
00043
00044 __version__ = "$Revision: 12660 $"
00045
00046
00047 import smtplib
00048 from email.mime.text import MIMEText
00049
00050
00051
00052
00053 def send_text_email(msg=None, subject=None, email_from=None, email_to=None) :
00054 """Sends e-mail.
00055 """
00056 dmsg = MIMEText(msg)
00057 dmsg['Subject'] = str(subject)
00058 dmsg['From'] = email_from
00059 dmsg['To'] = email_to
00060 s = smtplib.SMTP('localhost')
00061 s.sendmail(email_from, [email_to], dmsg.as_string())
00062 s.quit()
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 def test_send_text_email() :
00080 print 20*'_', '\n%s:' % sys._getframe().f_code.co_name
00081 log.setPrintBits(0377)
00082 send_text_email(msg='Test message',\
00083 subject='Test subject',\
00084 email_from='no-reply@slac.stanford.edu',\
00085 email_to='dubrovin@slac.stanford.edu')
00086
00087
00088
00089 def do_test() :
00090 tname = sys.argv[1] if len(sys.argv) > 1 else '0'
00091 print 50*'_', '\nTest %s:' % tname
00092 if tname == '0' : test_send_text_email()
00093 elif tname == '1' : test_send_text_email()
00094 else : print 'Not-recognized test: %s' % tname
00095 sys.exit('End of test %s' % tname)
00096
00097
00098
00099 if __name__ == "__main__" :
00100 import sys; global sys
00101 do_test()
00102
00103