def sendErrorMessage(msg): # We want to send an email so that the query doesn't silently fail # ---------------------------------------------------------------- args = cdr.Tier().name, "*** Error: Program CheckHotfixRemove failed!" subject = "[%s] %s" % args recips = cdr.getEmailList("Developers Notification") mailHeader = """\ From: %s To: %s Subject: %s """ % (STR_FROM, ", ".join(recips), subject) mailHeader += "Content-type: text/html; charset=utf-8\n" mailBody = "<b>Error running HotfixRemove.py</b><br>" mailBody += "Most likely %s<br>" % msg mailBody += "See log file for details." # Add a Separator line + body # --------------------------- message = mailHeader + "\n" + mailBody server = smtplib.SMTP(SMTP_RELAY) server.sendmail(STR_FROM, recips, message.encode('utf-8')) server.quit()
def sendFailureMessage(header="*** Error ***", body=""): emailDL = cdr.getEmailList('Test Publishing Notification') subject = header if not body: body = """ The publishing job failed. Please check the log files. """ opts = dict(subject=subject, body=body) cdr.EmailMessage(cdr.OPERATOR, emailDL, **opts).send() return
def alert(self, job): """ Send an email alert to the user to whom the translation job is currently assigned. """ recip = self.UserInfo(self, job.assigned_to) if not recip.email: error = f"no email address found for user {recip.name}" self.logger.error(error) self.bail(error) recips = [recip.email] sender = "*****@*****.**" body = [] subject = f"[{self.session.tier}] Translation Queue Notification" log_message = f"mailed translation job state alert to {recip}" if not isProdHost(): recips = getEmailList("Test Translation Queue Recips") body.append( f"[*** THIS IS A TEST MESSAGE ON THE {self.session.tier} TIER." f" ON PRODUCTION IT WOULD HAVE GONE TO {recip}. ***]\n" ) log_message = f"test alert for {recip} sent to {recips}" if self.job.new: body.append("A new translation job has been assigned to you.") else: body.append("A translation job assigned to you has a new status.") body.append(f"Assigned by: {self.user}") body.append(f"English summary document ID: CDR{job.english_id:d}") body.append(f"English summary title: {job.english_title}") if job.spanish_title: body.append(f"Spanish summary document ID: CDR{job.spanish_id:d}") body.append(f"Spanish summary title: {job.spanish_title}") body.append(f"Summary audience: {job.english_audience}") body.append(f"Job status: {self.states.map.get(job.state_id)}") state_date = str(job.state_date)[:10] body.append(f"Date of status transition: {state_date}") body.append(f"Comments: {job.comments}") opts = dict(subject=subject, body="\n".join(body)) if self.files: opts["attachments"] = self.files try: message = EmailMessage(sender, recips, **opts) message.send() except Exception as e: self.logger.error("sending mail: %s", e) self.bail(f"sending mail: {e}") self.logger.info(log_message)
mailBody += """\ </table> </body> </html> """ # In Testmode we don't want to send the notification to the world # --------------------------------------------------------------- # Email constants # --------------- SMTP_RELAY = "MAILFWD.NIH.GOV" strFrom = "PDQ Operator <*****@*****.**>" if testMode: strTo = cdr.getEmailList('Test Publishing Notification') else: strTo = cdr.getEmailList('Licensee Report Notification') args = cdr.Tier().name, 'PDQ Distribution Partner List' subject = "[%s] %s" % args mailHeader = """\ From: %s To: %s Subject: %s """ % (strFrom, ", ".join(strTo), subject) mailHeader += "Content-type: text/html; charset=iso-8859-1\n" # Add a Separator line + body
# -------------------------------------------------- if len(sys.argv) < 3: sys.stderr.write("\nusage: %s subject message\n" % os.path.basename(sys.argv[0])) sys.exit(1) # Open Log file and enter start message # ------------------------------------- LOGFILE = 'PubEmail.log' LOGGER = cdr.Logging.get_logger("PubEmail") LOGGER.info('PubEmail Notification - Started') LOGGER.info('Arguments: %s', sys.argv) # Retrieve the Email addresses from the specified group # ----------------------------------------------------- emailDL = sorted(cdr.getEmailList('Operator Publishing Notification')) emailDev = sorted(cdr.getEmailList("Developers Notification")) # Set the variables and send the message # -------------------------------------- sender = "*****@*****.**" subject = "[%s] %s" % (cdr.Tier().name, sys.argv[1]) message = """\ Automated Publishing Email Notification: %s""" % sys.argv[2] try: # Somebody needs to get the message if the group is empty if not len(emailDL): emailDL = emailDev
mailBody += """\ </table> </body> </html> """ else: raise NoNewDocumentsError('NoNewDocumentsError') # In Testmode we don't want to send the notification to the world # --------------------------------------------------------------- # Email constants # --------------- if testMode: strTo = cdr.getEmailList('Test Publishing Notification') else: strTo = cdr.getEmailList('Hotfix Remove Notification') #strTo.append(u'*****@*****.**') args = cdr.Tier().name, "Document Candidates to be removed from Cancer.gov" subject = "[%s] %s" % args mailHeader = """\ From: %s To: %s Subject: %s """ % (STR_FROM, ', '.join(strTo), subject) mailHeader += "Content-type: text/html; charset=utf-8\n"
# Optionally overriden below once we know the publishing subset. # -------------------------------------------------------------------- if cdr.isProdHost(): waitTotal = 10800 # 3.0 hours elif cdr.isDevHost(): waitTotal = 10800 # 3.0 hours else: waitTotal = 14400 # 4.0 hours testMode = None fullMode = None session = cdr.login("cdroperator", cdr.getpw("cdroperator")) pubSystem = 'Primary' pubEmail = cdr.getEmailList('Operator Publishing Notification') # ------------------------------------------------------------ # Function to parse the command line arguments # ------------------------------------------------------------ def parseArgs(args): # args = argv global testMode global fullMode global LOGGER try: shortopts = "tlie" longopts = ["testmode", "livemode", "interim", "export"]
html += delHeader % (reportTitles['del'], startDate, endDate) if delImages: delReport = createRows(delMediaChanges) html += tableHeader % delReport else: html += """ <p class="none">None</p> """ html += """ </body> </html>""" # Don't send emails to everyone if we're testing # ---------------------------------------------- emailDL = sorted(cdr.getEmailList('VOL Notification')) emailDevs = sorted(cdr.getEmailList("Developers Notification")) if not len(emailDL) or testMode: recips = emailDevs else: recips = emailDL allChanges = newMediaChanges + updMediaChanges + delMediaChanges email_opts = dict(subject=subject, body=html, subtype="html") if allChanges and recips: LOGGER.info("Sending Email to DL") LOGGER.info(" DL: %s", recips) LOGGER.info("\nEmail body:") LOGGER.info("-----------------------------------------------") LOGGER.info("%s", html) LOGGER.info("-----------------------------------------------\n")