def mailSendingExample(): bxoId = curGet_bxoId() sr = curGet_sr() sendingMethod = msgOut.SendingMethod.submit msg = email.message.Message() #msg = MIMEText() # MIMEMultipart() msg['From'] = fromLine msg['To'] = toLine msg['Subject'] = """Example Of A Simple And Tracked Message""" envelopeAddr = envelopeLine if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return msgOut.sendingMethodSet(msg, sendingMethod) msg.add_header('Content-Type', 'text') msg.set_payload(""" This is a simple example message with a simple attachment being sent using the current enabled controlledProfile and mailAcct. On the sending end, use mailAcctsManage.py with -i enabledControlProfileSet and -i enabledMailAcctSet to select the outgoing profile. The current settings are: ControlProfile={controlProfile} -- MailAcct={mailAcct} This message is then submitted for sending with sendCompleteMessage().cmnd(msg) """.format(controlProfile=marmeAcctsLib.enabledControlProfileObtain( curGet_bxoId(), curGet_sr(), ), mailAcct=marmeAcctsLib.enabledInMailAcctObtain( curGet_bxoId(), curGet_sr(), ))) # ########################### # # Above is the real content of the email. # # We now augment the message with: # - explicit envelope address -- To be used for Delivery-Status-Notifications (DSN) # - The email is to be tagged for crossReferencing when DSN is received (e.g. with peepid) # - Request that non-delivery-reports be acted upon and sent to co-recipients # - Explicit delivery-reports are requested # - Explicit read-receipts are requested # - Injection/Submission parameters are specified # The message is then sent out # msgOut.envelopeAddrSet( msg, mailBoxAddr=envelopeAddr, # Mandatory ) # # e.g., peepId will be used to crossRef StatusNotifications # msgOut.crossRefInfo( msg, crossRefInfo="XrefForStatusNotifications" # Mandatory ) # # Delivery Status Notifications will be sent to notifyTo=envelopeAddr # msgOut.nonDeliveryNotificationRequetsForTo( msg, notifyTo=envelopeAddr, ) # # In case of Non-Delivery, coRecipientsList will be informed # msgOut.nonDeliveryNotificationActions( msg, coRecipientsList=[toLine], ) # # Explicit Delivery Report is requested # msgOut.deliveryNotificationRequetsForTo( msg, recipientsList=[toLine], notifyTo=envelopeAddr, ) # # Explicit Read Receipt is requested # msgOut.dispositionNotificationRequetsForTo( msg, recipientsList=[toLine], notifyTo=envelopeAddr, ) if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return icm.EH_badLastOutcome() if not marmeSendLib.bx822Set_sendWithEnabledAcct( msg=msg, sendingMethod=sendingMethod, bxoId=bxoId, sr=sr, ): return icm.EH_badOutcome() marmeTrackingLib.trackDelivery_injectBefore( bxoId, sr, msg, ) cmndOutcome = marmeSendLib.sendCompleteMessage().cmnd( interactive=False, msg=msg, bxoId=bxoId, sr=sr, ) marmeTrackingLib.trackDelivery_injectAfter( bxoId, sr, msg, ) return cmndOutcome
def cmnd( self, interactive=False, # Can also be called non-interactively bxoId=None, # or Cmnd-Input sr=None, # or Cmnd-Input fromLine=None, # or Cmnd-Input toLine=None, # or Cmnd-Input sendingMethod=None, # or Cmnd-Input ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'bxoId': bxoId, 'sr': sr, 'fromLine': fromLine, 'toLine': toLine, 'sendingMethod': sendingMethod, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome bxoId = callParamsDict['bxoId'] sr = callParamsDict['sr'] fromLine = callParamsDict['fromLine'] toLine = callParamsDict['toLine'] sendingMethod = callParamsDict['sendingMethod'] ####+END: if not sendingMethod: sendingMethod = msgOut.SendingMethod.submit msg = MIMEMultipart() msg['From'] = fromLine msg['To'] = toLine msg['Subject'] = """Example Of A Simple And Untracked Message""" msg.preamble = 'Multipart massage.\n' part = MIMEText(""" This is a simple example message with a simple attachment being sent using the current enabled controlledProfile and mailAcct. On the sending end, use mailAcctsManage.py with -i enabledControlProfileSet and -i enabledMailAcctSet to select the outgoing profile. The current settings are: ControlProfile={controlProfile} -- MailAcct={mailAcct} This message is then submitted for sending with sendCompleteMessage().cmnd(msg) Please find example of an attached file\n """.format( controlProfile=marmeAcctsLib.enabledControlProfileObtain(), mailAcct=marmeAcctsLib.enabledInMailAcctObtain())) msg.attach(part) part = MIMEBase('application', "octet-stream") part.set_payload(open("/etc/resolv.conf", "rb").read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="/etc/resolv.conf"') msg.attach(part) if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return icm.EH_badLastOutcome() if not marmeSendLib.bx822Set_sendWithEnabledAcct( msg=msg, sendingMethod=sendingMethod, bxoId=bxoId, sr=sr, ): return icm.EH_badOutcome(cmndOutcome) cmndOutcome = marmeSendLib.sendCompleteMessage().cmnd( interactive=False, msg=msg, bxoId=bxoId, sr=sr, ) return cmndOutcome
def g_argsExtraSpecify(parser, ): ####+END: """Module Specific Command Line Parameters. g_argsExtraSpecify is passed to G_main and is executed before argsSetup (can not be decorated) """ G = icm.IcmGlobalContext() icmParams = icm.ICM_ParamDict() marmeAcctsLib.commonParamsSpecify(icmParams) icmParams.parDictAdd( parName='moduleVersion', parDescription="Module Version", parDataType=None, parDefault=None, parChoices=list(), parScope=icm.ICM_ParamScope.TargetParam, argparseShortOpt=None, argparseLongOpt='--version', ) icmParams.parDictAdd( parName='inFile', parDescription="Input File", parDataType=None, # ../control/outMail/common/template/bynameUtf8.mail parDefault=os.path.join( marmeAcctsLib.outMailCommonDirGet( marmeAcctsLib.enabledControlProfileObtain( curGet_bxoId(), curGet_sr())), "template/bynameUtf8.mail"), parChoices=["someFile", "UserInput"], parScope=icm.ICM_ParamScope.TargetParam, argparseShortOpt=None, argparseLongOpt='--inFile', ) icmParams.parDictAdd( parName='fromLine', parDescription="From Line", parDataType=None, parDefault="*****@*****.**", parChoices=["*****@*****.**", "UserInput"], parScope=icm.ICM_ParamScope.TargetParam, argparseShortOpt=None, argparseLongOpt='--fromLine', ) icmParams.parDictAdd( parName='toLine', parDescription="To Line", parDataType=None, parDefault="*****@*****.**", parChoices=["*****@*****.**", "UserInput"], parScope=icm.ICM_ParamScope.TargetParam, argparseShortOpt=None, argparseLongOpt='--toLine', ) bleep.commonParamsSpecify(icmParams) icm.argsparseBasedOnIcmParams(parser, icmParams) # So that it can be processed later as well. G.icmParamDictSet(icmParams) return
def cmnd( self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: icm.ex_gCommon() bleep.examples_icmBasic() # """ # ** [[elisp:(org-cycle)][| ]] [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(beginning-of-buffer)][Top]] [[elisp:(delete-other-windows)][(1)]] || Examples :: General Dev and Testing IIFs [[elisp:(org-cycle)][| ]] # """ # icm.cmndExampleMenuChapter('*General Dev and Testing IIFs*') # cmndName = "unitTest" ; cmndArgs = "" ; cps = collections.OrderedDict() # icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') """ ** [[elisp:(org-cycle)][| ]] [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(beginning-of-buffer)][Top]] [[elisp:(delete-other-windows)][(1)]] || Examples :: Default Mail From Complete File [[elisp:(org-cycle)][| ]] """ enabledControlProfile = marmeAcctsLib.enabledControlProfileObtain( curGet_bxoId(), curGet_sr()) enabledOutMailAcct = marmeAcctsLib.enabledOutMailAcctObtain( curGet_bxoId(), curGet_sr()) #enabledControlProfile = marmeAcctsLib.enabledControlProfileObtain() #enabledOutMailAcct = marmeAcctsLib.enabledOutMailAcctObtain() icm.cmndExampleMenuChapter( """*Mail From Complete File -- Default ControlProfile={controlProfile} Acct={mailAcct}*""" .format( controlProfile=enabledControlProfile, mailAcct=enabledOutMailAcct, )) cmndName = "sendCompleteMessage" cmndArgs = "" icm.cmndExampleMenuSection( """*Mail File fromValid/toValid -- Default ControlProfile={controlProfile} Acct={mailAcct}*""" .format(controlProfile=enabledControlProfile, mailAcct=enabledOutMailAcct)) inFileExample = '''{fileName}'''.format(fileName=os.path.join( marmeAcctsLib.outMailCommonDirGet( enabledControlProfile, curGet_bxoId(), curGet_sr(), ), "template/plain/fromValid/toValid/default.mail")) cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "runDebug" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='little') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "runDebug" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, icmWrapper="echo", verbosity='little') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "dryRun" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='little') icm.cmndExampleMenuSection( """*Mail File fromValid/toBad -- Default ControlProfile={controlProfile} Acct={mailAcct}*""" .format( controlProfile=enabledControlProfile, mailAcct=enabledOutMailAcct, )) inFileExample = '''{fileName}'''.format(fileName=os.path.join( marmeAcctsLib.outMailCommonDirGet( enabledControlProfile, curGet_bxoId(), curGet_sr(), ), "template/plain/fromValid/toBad/default.mail")) cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "runDebug" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='little') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "runDebug" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, icmWrapper="echo", verbosity='little') cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['runMode'] = "dryRun" cps['inFile'] = inFileExample icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='little') """ ** [[elisp:(org-cycle)][| ]] [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(beginning-of-buffer)][Top]] [[elisp:(delete-other-windows)][(1)]] || Examples :: Mail From Partial File -- Qmail Inject [[elisp:(org-cycle)][| ]] """ icm.cmndExampleMenuChapter('*Mail From Partial File -- Qmail Inject*') inFileExample = '''{fileName}'''.format(fileName=os.path.join( marmeAcctsLib.outMailCommonDirGet( enabledControlProfile, curGet_bxoId(), curGet_sr(), ), "template/bynameUtf8.mail")) cmndName = "sendFromPartialFileWithPars" cmndArgs = "" cps = collections.OrderedDict() cps['submissionMethod'] = "inject" cps['inFile'] = inFileExample cps['runMode'] = "dryRun" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') """ ** [[elisp:(org-cycle)][| ]] [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(beginning-of-buffer)][Top]] [[elisp:(delete-other-windows)][(1)]] || Examples :: Basic Mail Sending [[elisp:(org-cycle)][| ]] """ icm.cmndExampleMenuChapter('*Basic Mail Sending*') cmndName = "msgSend_basic" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cmndName = "msgSend_basic" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['verbosity'] = "20" cps['runMode'] = "runDebug" cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cmndName = "msgSend_basic" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['verbosity'] = "20" cps['runMode'] = "dryRun" cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cmndName = "msgSend_tracked" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cmndName = "msgSend_tracked" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['verbosity'] = "20" cps['runMode'] = "runDebug" cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') cmndName = "msgSend_tracked" cmndArgs = "" cps = collections.OrderedDict() cmndParsCurBxoSr(cps) cps['verbosity'] = "20" cps['runMode'] = "dryRun" cps['fromLine'] = "*****@*****.**" cps['toLine'] = "*****@*****.**" icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity='none') """ ** [[elisp:(org-cycle)][| ]] [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(beginning-of-buffer)][Top]] [[elisp:(delete-other-windows)][(1)]] || Examples :: From marmeAcctsLib.py [[elisp:(org-cycle)][| ]] """ marmeAcctsLib.examples_controlProfileManage() marmeAcctsLib.examples_enabledOutMailAcctConfig() marmeAcctsLib.examples_outMailAcctAccessPars() return (cmndOutcome)
def cmnd( self, interactive=False, # Can also be called non-interactively ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = {} if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome ####+END: def cpsInit(): return collections.OrderedDict() def menuItem(verbosity): icm.ex_gCmndMenuItem(cmndName, cps, cmndArgs, verbosity=verbosity) # 'little' or 'none' def execLineEx(cmndStr): icm.ex_gExecMenuItem(execLine=cmndStr) logControler = icm.LOG_Control() logControler.loggerSetLevel(20) icm.icmExampleMyName(G.icmMyName(), G.icmMyFullName()) icm.G_commonBriefExamples() bleep.examples_icmBasic() controlProfile = marmeAcctsLib.enabledControlProfileObtain( curGet_bxoId(), curGet_sr()) defaultMailDom = marmeAcctsLib.enabledInMailAcctObtain( curGet_bxoId(), curGet_sr()) ####+BEGIN: bx:icm:python:cmnd:subSection :title "Dev And Testing" """ ** [[elisp:(beginning-of-buffer)][Top]] ================ [[elisp:(blee:ppmm:org-mode-toggle)][Nat]] [[elisp:(delete-other-windows)][(1)]] *Dev And Testing* [[elisp:(org-cycle)][| ]] [[elisp:(org-show-subtree)][|=]] """ ####+END: #icm.cmndExampleMenuChapter('*General Dev and Testing IIFs*') icm.cmndExampleMenuChapter('*Config File Creation Facility IIFs*') cmndName = "offlineimaprcUpdate" cmndArgs = "" cps = cpsInit() cmndParsCurBxoSr(cps) menuItem(verbosity='none') menuItem(verbosity='full') cmndName = "offlineimaprcStdout" cmndArgs = "" cps = cpsInit() cmndParsCurBxoSr(cps) menuItem(verbosity='none') menuItem(verbosity='full') configFile = withInMailDomGetOfflineimaprcPath( controlProfile, defaultMailDom, curGet_bxoId(), curGet_sr(), ) icm.ANN_write("""ls -l {}""".format(configFile)) icm.ANN_write("""cat {} """.format(configFile)) icm.cmndExampleMenuChapter( '*Operation Facility IIFs -- (offlineimapRun)*') cmndName = "offlineimapRun" cmndArgs = "" cps = cpsInit() cmndParsCurBxoSr(cps) menuItem(verbosity='none') menuItem(verbosity='full') marmeAcctsLib.examples_controlProfileManage() #marmeAcctsLib.examples_marmeAcctsLibControls() marmeAcctsLib.examples_enabledInMailAcctConfig() marmeAcctsLib.examples_inMailAcctAccessPars()