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 msgSendingPipelineLoadFromAcctBaseDir( msg, acctBaseDir, ): """ ** Read File Params for mailAcct and set X822-MSP params accordingly """ opOutcome = icm.OpOutcome() #print acctBaseDir #G = icm.IcmGlobalContext() outcome = icm.FP_readTreeAtBaseDir().cmnd( interactive=False, FPsDir=os.path.join(acctBaseDir, 'access'), ) fp_access_dict = outcome.results outcome = icm.FP_readTreeAtBaseDir().cmnd( interactive=False, FPsDir=os.path.join(acctBaseDir, 'controllerInfo'), ) #fp_controllerInfo_dict = outcome.results outcome = icm.FP_readTreeAtBaseDir().cmnd( interactive=False, FPsDir=os.path.join(acctBaseDir, 'submission'), ) fp_submission_dict = outcome.results envelopeAddr = fp_submission_dict["envelopeAddr"].parValueGet() msgOut.envelopeAddrSet( msg, mailBoxAddr=envelopeAddr, # Mandatory ) sendingMethod = fp_submission_dict["sendingMethod"].parValueGet() if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return icm.EH_badLastOutcome() if sendingMethod == msgOut.SendingMethod.inject: return opOutcome # # So, It is a submission # # NOTYET, below should be split and use # msgOut.submitParamsNOT() # try: mtaRemHost = fp_access_dict["mtaRemHost"].parValueGet() except KeyError: return icm.eh_problem_usageError(opOutcome, "Missing BX-MTA-Rem-Host") try: userName = fp_access_dict["userName"].parValueGet() except KeyError: return icm.eh_problem_usageError(opOutcome, "Missing BX-MTA-Rem-User") try: userPasswd = fp_access_dict["userPasswd"].parValueGet() except KeyError: return icm.eh_problem_usageError(opOutcome, "Missing BX-MTA-Rem-Passwd") try: remProtocol = fp_access_dict["mtaRemProtocol"].parValueGet() except KeyError: return icm.eh_problem_usageError(opOutcome, "Missing BX-MTA-Rem-Protocol") try: remPortNu = fp_access_dict["mtaRemPortNu"].parValueGet() except KeyError: remPortNu = None msgOut.submitParams( msg, mtaRemProtocol=remProtocol, # smtp mtaRemHost=mtaRemHost, # Remote Host To Submit to (could be localhost) mtaRemPort=remPortNu, mtaRemUser=userName, mtaRemPasswd=userPasswd, mtaRemCerts=None, ) return opOutcome
def cmnd( self, interactive=False, # Can also be called non-interactively outMailAcct=None, # or Cmnd-Input inFile=None, # or Cmnd-Input sendingMethod=None, # or Cmnd-Input msg=None, # asFunc when interactive==False ): cmndOutcome = self.getOpOutcome() if interactive: if not self.cmndLineValidate(outcome=cmndOutcome): return cmndOutcome callParamsDict = { 'outMailAcct': outMailAcct, 'inFile': inFile, 'sendingMethod': sendingMethod, } if not icm.cmndCallParamsValidate( callParamsDict, interactive, outcome=cmndOutcome): return cmndOutcome outMailAcct = callParamsDict['outMailAcct'] inFile = callParamsDict['inFile'] sendingMethod = callParamsDict['sendingMethod'] ####+END: G = icm.IcmGlobalContext() if not msg: if inFile: msg = msgIn.getMsgFromFile(inFile) else: # Stdin then msg = msgIn.getMsgFromStdin() icm.LOG_here(msgOut.strLogMessage( "Msg As Input:", msg, )) if not sendingMethod: sendingMethod = msgOut.SendingMethod.submit if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return msgOut.sendingMethodSet(msg, sendingMethod) print(G.usageParams.runMode) if msgOut.sendingRunControlSet(msg, G.usageParams.runMode).isProblematic(): return msgOut.sendingRunControlSet(msg, G.usageParams.runMode) envelopeAddr = msg['From'] recipientsList = msg['To'] msgOut.envelopeAddrSet( msg, mailBoxAddr=envelopeAddr, # Mandatory ) msgOut.crossRefInfo( msg, crossRefInfo="XrefForStatusNotifications" # Mandatory ) msgOut.nonDeliveryNotificationRequetsForTo( msg, recipientsList=recipientsList, notifyTo=envelopeAddr, ) msgOut.nonDeliveryNotificationActions( msg, coRecipientsList=recipientsList, ) msgOut.deliveryNotificationRequetsForTo( msg, recipientsList=recipientsList, notifyTo=envelopeAddr, ) msgOut.dispositionNotificationRequetsForTo( msg, recipientsList=recipientsList, notifyTo=envelopeAddr, ) if msgOut.sendingMethodSet(msg, sendingMethod).isProblematic(): return icm.EH_badLastOutcome() if not marmeSendLib.bx822Set_sendWithEnabledAcct(msg, sendingMethod): return icm.EH_badOutcome(cmndOutcome) cmndOutcome = marmeSendLib.sendCompleteMessage().cmnd( interactive=False, msg=msg, ) return cmndOutcome