def _sendErrorEmail(self, e): ty, ex, tb = sys.exc_info() tracebackList = traceback.format_list(traceback.extract_tb(tb)) text = ( _( """ Offline website creation for the [event:%s] had caused an error while running the task. - Request from user: %s <%s> - Details of the exception: %s - Traceback: %s -- <Indico support> indico-project @ cern.ch """ ) % (self._conf.getId(), self._toUser.getFullName(), self._toUser.getEmail(), e, "\n".join(tracebackList)) ) maildata = { "fromAddr": Config.getInstance().getSupportEmail(), "toList": [Config.getInstance().getSupportEmail()], "subject": _("[Indico] Error in task: Offline website creation"), "body": text, } GenericMailer.send(GenericNotification(maildata))
def _sendMail(self, currentList, newManager): if isinstance(newManager, AvatarUserWrapper): managerName = newManager.getStraightFullName() else: managerName = newManager.getName() text = ( _( """Dear managers, %s has been added as manager for the category '%s': %s Best regards, Indico Team """ ) % (managerName, self._categ.getName(), UHCategModifAC.getURL(self._categ)) ) maildata = { "fromAddr": "%s" % Config.getInstance().getNoReplyEmail(), "toList": [manager.getEmail() for manager in currentList], "subject": "New category manager", "body": text, } GenericMailer.send(GenericNotification(maildata))
def _sendReport( self ): cfg = Config.getInstance() # if no e-mail address was specified, # add a default one if self._userMail: fromAddr = self._userMail else: fromAddr = '*****@*****.**' toAddr = Config.getInstance().getSupportEmail() Logger.get('errorReport').debug('mailing %s' % toAddr) subject = "[Indico@%s] Error report"%cfg.getBaseURL() request_info = self._requestInfo or '' if isinstance(request_info, (dict, list)): request_info = pformat(request_info) # build the message body body = [ "-" * 20, "Error details\n", self._code, self._message, "Inner error: " + str(self._inner), request_info, "-" * 20 ] maildata = {"fromAddr": fromAddr, "toList": [toAddr], "subject": subject, "body": "\n".join(body)} GenericMailer.send(GenericNotification(maildata))
def notify(self,registrant,params): if params.has_key("conf"): GenericMailer.sendAndLog(self.apply(registrant,params), params["conf"], 'Registration') else: GenericMailer.send(self.apply(registrant,params))
def _sendReport(self): info = HelperMaKaCInfo().getMaKaCInfoInstance() cfg = Config.getInstance() # if no e-mail address was specified, # add a default one if self._userMail: fromAddr = self._userMail else: fromAddr = "*****@*****.**" toAddr = info.getSupportEmail() Logger.get("errorReport").debug("mailing %s" % toAddr) subject = "[Indico@%s] Error report" % cfg.getBaseURL() # build the message body body = [ "-" * 20, "Error details\n", self._code, self._message, "Inner error: " + str(self._inner), str(self._requestInfo), "-" * 20, ] maildata = {"fromAddr": fromAddr, "toList": [toAddr], "subject": subject, "body": "\n".join(body)} # send it GenericMailer.send(GenericNotification(maildata))
def _sendReport(self): cfg = Config.getInstance() # if no e-mail address was specified, # add a default one if self._userMail: fromAddr = self._userMail else: fromAddr = '*****@*****.**' toAddr = Config.getInstance().getSupportEmail() Logger.get('errorReport').debug('mailing %s' % toAddr) subject = "[Indico@{}] Error report".format( url_parse(cfg.getBaseURL()).netloc) request_info = self._requestInfo or '' if isinstance(request_info, (dict, list)): request_info = pformat(request_info) # build the message body body = [ "-" * 20, "Error details\n", self._code, self._message, "Inner error: " + str(self._inner), request_info, "-" * 20 ] maildata = { "fromAddr": fromAddr, "toList": [toAddr], "subject": subject, "body": "\n".join(body) } GenericMailer.send(GenericNotification(maildata))
def run(self, check=True): import smtplib from MaKaC.webinterface.mail import GenericMailer, GenericNotification # prepare the mail send = self._prepare(check=check) # _prepare decided we shouldn't send the mail? if not send: return # just in case some ill-behaved code generates empty addresses addrs = list(smtplib.quoteaddr(x) for x in self.toAddr if x) ccaddrs = list(smtplib.quoteaddr(x) for x in self.ccAddr if x) if len(addrs) + len(ccaddrs) == 0: self.getLogger().warning("Attention: no recipients, mail won't be sent") else: self.getLogger().info("Sending mail To: %s, CC: %s" % (addrs, ccaddrs)) for user in self.toUser: addrs.append(smtplib.quoteaddr(user.getEmail())) if addrs or ccaddrs: GenericMailer.send(GenericNotification({"fromAddr": self.fromAddr, "toList": addrs, "ccList": ccaddrs, "subject": self.subject, "body": self.text }))
def _sendErrorEmail(self, e): ty, ex, tb = sys.exc_info() tracebackList = traceback.format_list(traceback.extract_tb(tb)) text = _(""" Offline website creation for the [event:%s] had caused an error while running the task. - Request from user: %s <%s> - Details of the exception: %s - Traceback: %s -- <Indico support> indico-project @ cern.ch """) % (self._conf.getId(), self._toUser.getFullName(), self._toUser.getEmail(), e, "\n".join(tracebackList)) maildata = { "fromAddr": Config.getInstance().getSupportEmail(), "toList": [Config.getInstance().getSupportEmail()], "subject": _("[Indico] Error in task: Offline website creation"), "body": text } GenericMailer.send(GenericNotification(maildata))
def notify(self,registrant,params): if params.has_key("conf"): GenericMailer.sendAndLog(self.apply(registrant,params), params["conf"], log.ModuleNames.REGISTRATION) else: GenericMailer.send(self.apply(registrant,params))
def notify(self, abstract, tpl): #if no from address is specified we should put the default one if tpl.getFromAddr().strip() == "": tpl.setFromAddr(tpl.getConference().getSupportInfo().getEmail( returnNoReply=True)) GenericMailer.send(self.apply(abstract, tpl))
def run(self, check=True): import smtplib from MaKaC.webinterface.mail import GenericMailer, GenericNotification # prepare the mail send = self._prepare(check=check) # _prepare decided we shouldn't send the mail? if not send: return addrs = [smtplib.quoteaddr(x) for x in self.toAddr] ccaddrs = [smtplib.quoteaddr(x) for x in self.ccAddr] if len(addrs) + len(ccaddrs) == 0: self.getLogger().warning("Attention: mail contains no recipients!") else: self.getLogger().info("Sending mail To: %s, CC: %s" % (addrs, ccaddrs)) for user in self.toUser: addrs.append(smtplib.quoteaddr(user.getEmail())) GenericMailer.send( GenericNotification( { "fromAddr": self.fromAddr, "toList": addrs, "ccList": ccaddrs, "subject": self.subject, "body": self.text, } ) )
def _sendReport(self): cfg = Config.getInstance() fromAddr = self._userMail toAddr = cfg.getSupportEmail() subject = "[Indico@%s] Error report" % cfg.getBaseURL() body = ["-"*20, "User Comments\n", "%s\n\n" % self._comments, "-"*20, "Error details\n", self._msg, "-" * 20] maildata = {"fromAddr": fromAddr, "toList": [toAddr], "subject": subject, "body": "\n".join(body)} GenericMailer.send(GenericNotification(maildata), skipQueue=True)
def run(self): addrs = [] ccaddrs = [] for addr in self.toAddr: addrs.append(smtplib.quoteaddr(addr)) for ccaddr in self.ccAddr: ccaddrs.append(smtplib.quoteaddr(ccaddr)) for user in self.toUser: addrs.append(smtplib.quoteaddr(user.getEmail())) maildata = { "fromAddr": self.fromAddr, "toList": addrs, "ccList": ccaddrs, "subject": self.subject, "body": self.text } GenericMailer.send(GenericNotification(maildata))
def notifyAll(self,params): subj=params.get("subject","") b=params.get("body","") fa=params.get("from","") tl=params.get("to",[]) cc = params.get("cc",[]) notification = Notification(subject=subj,body=b,fromAddr=fa,toList=tl,ccList=cc) if params.has_key("conf"): GenericMailer.sendAndLog(notification, params["conf"]) else: GenericMailer.send(notification)
def notifyAll(self,params): subj=params.get("subject","") b=params.get("body","") fa=params.get("from","") tl=params.get("to",[]) cc = params.get("cc",[]) notification = Notification(subject=subj,body=b,fromAddr=fa,toList=tl,ccList=cc) if params.has_key("conf"): GenericMailer.sendAndLog(notification, params["conf"], log.ModuleNames.REGISTRATION) else: GenericMailer.send(notification)
def addPendingParticipant(self, participant): if participant.getConference().getId() != self._conference.getId(): return False if participant.getId() is not None: return False if self.alreadyParticipating(participant) != 0: return False if self.getAutoAccept(): self.addParticipant(participant) else: self._pendingParticipantList["%d" % self._newPendingId()] = participant logData = participant.getParticipantData() logData["subject"] = _( "New pending participant : %s") % participant.getWholeName() self._conference.getLogHandler().logAction(logData, "participants") participant.setStatusPending() profileURL = urlHandlers.UHConfModifParticipantsPendingDetails.getURL( self._conference) profileURL.addParam("pendingId", self._lastPendingId()) toList = [] creator = self._conference.getCreator() if isinstance(creator, Avatar): toList.append(creator.getEmail()) for manager in self._conference.getAccessController( ).getModifierList(): if isinstance(manager, Avatar): toList.append(manager.getEmail()) data = {} data["toList"] = toList data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance( ).getSupportEmail() data["subject"] = _("New pending participant for %s" ) % self._conference.getTitle() data["body"] = _(""" Dear Event Manager, a new person is asking for participation in %s. Personal profile of this pending participant is available at %s Please take this candidature into consideration and accept or reject it Your Indico """) % (self._conference.getTitle(), profileURL) GenericMailer.send(GenericNotification(data)) self.notifyModification() return True
def _sendEmail(self, ofu): text = _(""" Offline website creation for your event was finished and you can recover the zip file from the following URL: <%s> Thanks for using Indico -- Indico """)%ofu maildata = { "fromAddr": Config.getInstance().getSupportEmail(), "toList": [self._toUser.getEmail()], "subject": _("[Indico] Offline website creation done"), "body": text } GenericMailer.send(GenericNotification(maildata))
def _sendEmail(self, ofu): text = _(""" Offline website creation for your event was finished and you can recover the zip file from the following URL: <%s> Thanks for using Indico -- Indico """)%ofu maildata = { "fromAddr": info.HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail(), "toList": [self._toUser.getEmail()], "subject": _("[Indico] Offline website creation done"), "body": text } GenericMailer.send(GenericNotification(maildata))
def _process( self ): count = 0 for abstract in self._abstracts: dict = AbstractNotification(self._conf, abstract).getDict() s = self._notifTpl.getTplSubject() b = self._notifTpl.getTplBody() maildata = { "fromAddr": self._notifTpl.getFromAddr(), "toList": [abstract.getSubmitter().getEmail()], "subject": s%dict, "body": text } GenericMailer.send(GenericNotification(maildata)) self._conf.newSentMail(abstract.getSubmitter(), mail.getSubject(), b%dict) count += 1 #self._redirect(urlHandlers.UHConfAbstractManagment.getURL(self._conf)) p = conferences.WPAbstractSendNotificationMail(self, self._conf, count ) return p.display()
def _sendMail(self, currentList, newManager): if isinstance(newManager, AvatarUserWrapper): managerName = newManager.getStraightFullName() else: managerName = newManager.getName() text = _("""Dear managers, %s has been added as manager for the category '%s': %s Best regards, Indico Team """) % (managerName, self._categ.getName(), UHCategModifAC.getURL(self._categ)) maildata = { "fromAddr": "%s" % Config.getInstance().getNoReplyEmail(), "toList": [manager.getEmail() for manager in currentList], "subject": "New category manager", "body": text } GenericMailer.send(GenericNotification(maildata))
def addPendingParticipant(self, participant): if participant.getConference().getId() != self._conference.getId() : return False if participant.getId() is not None : return False if self.alreadyParticipating(participant) != 0 : return False if self.isAutoAccept(): self.addParticipant(participant) else: self._pendingParticipantList["%d"%self._newPendingId()] = participant logData = participant.getParticipantData() logData["subject"] = _("New pending participant : %s")%participant.getWholeName() self._conference.getLogHandler().logAction(logData, log.ModuleNames.PARTICIPANTS) participant.setStatusPending() profileURL = urlHandlers.UHConfModifParticipantsPending.getURL(self._conference) toList = [] creator=self._conference.getCreator() if isinstance(creator, Avatar) : toList.append(creator.getEmail()) for manager in self._conference.getAccessController().getModifierList() : if isinstance(manager, Avatar) : toList.append(manager.getEmail()) data = {} data["toList"] = toList data["fromAddr"] = Config.getInstance().getSupportEmail() data["subject"] = _("New pending participant for %s")%self._conference.getTitle() data["body"] = """ Dear Event Manager, a new person is asking for participation in %s. Personal profile of this pending participant is available at %s Please take this candidature into consideration and accept or reject it Your Indico """%(self._conference.getTitle(), profileURL) GenericMailer.send(GenericNotification(data)) self.notifyModification() return True
def _sendSecondaryEmailNotifiication(self, email): data = {} data["toList"] = [email] data["fromAddr"] = Config.getInstance().getSupportEmail() data["subject"] = """[Indico] Email address confirmation""" data["body"] = """Dear %s, You have added a new email to your secondary email list. In order to confirm and activate this new email address, please open in your web browser the following URL: %s Once you have done it, the email address will appear in your profile. Best regards, Indico Team""" % (self._user.getStraightFullName(), url_for('user.userRegistration-validateSecondaryEmail', userId=self._user.getId(), key=md5(email).hexdigest(), _external=True)) GenericMailer.send(GenericNotification(data))
def addPendingParticipant(self, participant): if participant.getConference().getId() != self._conference.getId() : return False if participant.getId() is not None : return False if self.alreadyParticipating(participant) != 0 : return False if self.isAutoAccept(): self.addParticipant(participant) else: self._pendingParticipantList["%d"%self._newPendingId()] = participant self.getConference().log(EventLogRealm.participants, EventLogKind.positive, u'Participants', u'New participation request: {}'.format(to_unicode(participant.getName())), session.user, data=participant.getParticipantData()) participant.setStatusPending() profileURL = urlHandlers.UHConfModifParticipantsPending.getURL(self._conference) data = {} data["toList"] = self._conference.all_manager_emails data["fromAddr"] = Config.getInstance().getSupportEmail() data["subject"] = _("New pending participant for %s")%self._conference.getTitle() data["body"] = """ Dear Event Manager, a new person is asking for participation in %s. Personal profile of this pending participant is available at %s Please take this candidature into consideration and accept or reject it Your Indico """%(self._conference.getTitle(), profileURL) GenericMailer.send(GenericNotification(data)) self.notifyModification() return True
def sendNegotiationInfo(self): if self._dateNgotiation is None : return False if not self._dateNegotiation.isFinished() : return False data = {} data["fromAddr"] = Config.getInstance().getNoReplyEmail() if len(self._dateNegotiation.getSolutionList()) == 0: """ TODO: Prepate URLs..!! """ settingURL = ">>must be prepared yet..!!<<" data["subject"] = _("Negotiation algorithm finished - FAILED to find date") toList = [] for manager in self._conference.getManagerList() : if isinstance(manager, Avatar) : toList.append(manager.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Event Manager, negotiation algorithm has finished its work on finding the date for %s, yet it didn't managed to find any solution satisfying all (or almost all) given restrictions. Setting the event's date is now up to you at %s Your Indico """)%(self._conference.getTitle(), settingURL) elif not self.dateNegotiation.isAutomatic : """ TODO: Prepate URLs..!! """ choseURL = ">>must be prepared yet..!!<<" data["subject"] = _("Negotiation algorithm finished - SUCCSEEDED") toList = [] for manager in self._conference.getManagerList() : if isinstance(manager, Avatar) : toList.append(manager.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Event Manager, negotiation algorithm has finished its work on finding the date for %s, now you are kindly requested to choose the most siutable date from the list of solution which is avaliable at %s Your Indico """)%(self._conference.getTitle(), choseURL) else : data["subject"] = _("Date of the %s setteled")%self._conference.getTitle() toList = [] for p in self._participantList.valuess() : toList.append(p.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Participant, negotiation algorithm has just set the date of the %s to : start date : %s end date : %s Wishing you a pleasent and interesting time - Your Indico """)%(self._conference.getTitle(), \ self._conference.getAdjustedStartDate(), self._conference.getAdjustedEndDate()) GenericMailer.send(GenericNotification(data)) return True
def _confirm_email_address(self, email, data_type): email = email.strip().lower() if not validMail(email): raise NoReportError(_("Invalid email address: {0}").format(email)) # Prevent adding the primary email as a secondary email if data_type == 'secondaryEmails' and email == self._avatar.getEmail(): raise NoReportError(_("{0} is already the primary email address " "and cannot be used as a secondary email address.").format(email)) # When setting a secondary email as primary, set it automatically and # re-index the user's emails without sending a confirmation email # (We assume the secondary emails are valid) if data_type == 'email' and email in self._avatar.getSecondaryEmails(): self._avatar.removeSecondaryEmail(email) self._avatar.setEmail(email, reindex=True) return False existing = AvatarHolder().match({'email': email}, searchInAuthenticators=False) if existing: if any(av for av in existing if av != self._avatar): raise NoReportError(_("The email address {0} is already used by another user.").format(email)) else: # The email is already set correctly for the user: Do nothing return False # New email address token_storage = GenericCache('confirm-email') data = {'email': email, 'data_type': data_type, 'uid': self._avatar.getId()} token = str(uuid.uuid4()) while token_storage.get(token): token = str(uuid.uuid4()) token_storage.set(token, data, 24 * 3600) url = url_for('user.confirm_email', token=token, _external=True, _secure=True) if data_type == 'email': body_format = _( "Dear {0},\n" "You requested to change your account's primary email address.\n" "Please open the link below within 24 hours to confirm and activate this email address:\n" "\n{1}\n\n" "--\n" "Indico" ) else: body_format = _( "Dear {0},\n" "You added this email address to your account's secondary emails list.\n" "Please open the link below within 24 hours to confirm and activate this email address:\n" "\n{1}\n\n" "--\n" "Indico" ) confirmation = { 'toList': [email], 'fromAddr': Config.getInstance().getSupportEmail(), 'subject': _("[Indico] Verify your email address"), 'body': body_format.format(self._avatar.getFirstName(), url) } # Send mail with template message and link GenericMailer.send(GenericNotification(confirmation)) return True
def sendNegotiationInfo(self): if self._dateNgotiation is None: return False if not self._dateNegotiation.isFinished(): return False data = {} data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance( ).getSupportEmail() if len(self._dateNegotiation.getSolutionList()) == 0: """ TODO: Prepate URLs..!! """ settingURL = ">>must be prepared yet..!!<<" data["subject"] = _( "Negotiation algorithm finished - FAILED to find date") toList = [] for manager in self._conference.getManagerList(): if isinstance(manager, Avatar): toList.append(manager.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Event Manager, negotiation algorithm has finished its work on finding the date for %s, yet it didn't managed to find any solution satisfying all (or almost all) given restrictions. Setting the event's date is now up to you at %s Your Indico """) % (self._conference.getTitle(), settingURL) elif not self.dateNegotiation.isAutomatic: """ TODO: Prepate URLs..!! """ choseURL = ">>must be prepared yet..!!<<" data["subject"] = _("Negotiation algorithm finished - SUCCSEEDED") toList = [] for manager in self._conference.getManagerList(): if isinstance(manager, Avatar): toList.append(manager.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Event Manager, negotiation algorithm has finished its work on finding the date for %s, now you are kindly requested to choose the most siutable date from the list of solution which is avaliable at %s Your Indico """) % (self._conference.getTitle(), choseURL) else: data["subject"] = _( "Date of the %s setteled") % self._conference.getTitle() toList = [] for p in self._participantList.valuess(): toList.append(p.getEmail()) data["toList"] = toList data["body"] = _(""" Dear Participant, negotiation algorithm has just set the date of the %s to : start date : %s end date : %s Wishing you a pleasent and interesting time - Your Indico """)%(self._conference.getTitle(), \ self._conference.getAdjustedStartDate(), self._conference.getAdjustedEndDate()) GenericMailer.send(GenericNotification(data)) return True
def notify(self, registrant, params): if params.has_key("conf"): GenericMailer.sendAndLog(self.apply(registrant, params), params["conf"], 'Registration') else: GenericMailer.send(self.apply(registrant, params))
def notify(self, abstract, tpl): # if no from address is specified we should put the default one if tpl.getFromAddr().strip() == "": tpl.setFromAddr(tpl.getConference().getSupportInfo().getEmail(returnNoReply=True)) GenericMailer.send(self.apply(abstract, tpl))
def notify(self,abstract,tpl): sm=GenericMailer.send(self.apply(abstract,tpl))
def _sendEmails( self ): if hasattr( self, "_emailsToBeSent" ): for email in self._emailsToBeSent: GenericMailer.send(GenericNotification(email))
def _sendEmails(self): if hasattr(self, "_emailsToBeSent"): for email in self._emailsToBeSent: GenericMailer.send(GenericNotification(email))