def emailrequest(request): """Send HTTP request headers to provided email address.""" resp = framework.ResponseDocument(request, doc_constructor, title="Web Responder") recipients = request.GET.getlist("recipient") + request.GET.getlist( "rcpt") or resp.config.ADMINS # some basic validation. Mailer shuould validate the rest. recipients = filter(lambda name: "@" in name, recipients) recipients = filter(lambda name: "." in name, recipients) if recipients: rpt = XHTML.new_document() get_header_table(rpt.body, request.environ) body = ezmail.AutoMessage(EMAILBODY) body["Content-Disposition"] = 'inline' msg = ezmail.AutoMessage(str(rpt), mimetype=rpt.MIMETYPE, charset=rpt.encoding) msg["Content-Disposition"] = 'attachment; filename=headers.html' ezmail.mail([body, msg], To=recipients, subject="Webtool header request from %s." % (request.environ.get("REMOTE_ADDR", "<unknown>"), )) get_header_table(resp.doc.content, request.environ) if recipients: resp.doc.content.new_para("Header data emailed to %s." % (", ".join(recipients), )) else: resp.doc.content.new_para("No valid email recipients.") return resp.finalize()
def __call__(self, timestamp, ip, community, pdu): tr = traps.TrapRecord(timestamp, ip, community, pdu) ezmail.mail(str(tr), To=self._recipients, From=self._from, subject="Trap from %r" % (str(ip), )) return False
def emailrequest(request): """Send HTTP request headers to provided email address.""" resp = framework.ResponseDocument(request, doc_constructor, title="Web Responder") recipients = request.GET.getlist("recipient")+request.GET.getlist("rcpt") or resp.config.ADMINS # some basic validation. Mailer shuould validate the rest. recipients = filter(lambda name: "@" in name, recipients) recipients = filter(lambda name: "." in name, recipients) if recipients: rpt = XHTML.new_document() get_header_table(rpt.body, request.environ) body = ezmail.AutoMessage(EMAILBODY) body["Content-Disposition"] = 'inline' msg = ezmail.AutoMessage(str(rpt), mimetype=rpt.MIMETYPE, charset=rpt.encoding) msg["Content-Disposition"] = 'attachment; filename=headers.html' ezmail.mail([body, msg], To=recipients, subject="Webtool header request from %s." % (request.environ.get("REMOTE_ADDR", "<unknown>"),)) get_header_table(resp.doc.content, request.environ) if recipients: resp.doc.content.new_para("Header data emailed to %s." % (", ".join(recipients),)) else: resp.doc.content.new_para("No valid email recipients.") return resp.finalize()
def mailmessage(cp): parts = [] # main message text and subject line body = CF.mail.body(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) parts.append(body) subj = CF.mail.Subject(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) # ogg file attachment oggfile = tempfile.NamedTemporaryFile(suffix=".ogg", prefix="voicemail", dir="/var/tmp") Vgetty.rmd2ogg(cp.inname, oggfile.name) oggfile.seek(0) ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg") ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename(cp.inname.replace("rmd", "ogg")), ) oggfile.close() parts.append(ogg) # mail it! ezmail.mail(parts, subject=subj, To=CF.mail.To)
def finalize(self): """finalizing this Report sends off the email.""" self.write(self._formatter.finalize()) report = ezmail.MIMEText.MIMEText(self._fo.getvalue(), self._formatter.MIMETYPE.split("/")[1]) report["Content-Disposition"] = "inline" self._message.attach(report) if self._logfile: try: lfd = open(self._logfile).read() except: pass # non-fatal print >>sys.stderr, "could not read or attach log file: %r" % (self._logfile,) else: logmsg = ezmail.MIMEText.MIMEText(lfd) logmsg["Content-Disposition"] = 'attachment; filename=%s' % (os.path.basename(self._logfile), ) self._message.attach(logmsg) ezmail.mail(self._message)
def finalize(self): """finalizing this Report sends off the email.""" self.write(self._formatter.finalize()) report = ezmail.MIMEText.MIMEText(self._fo.getvalue(), self._formatter.MIMETYPE.split("/")[1]) report["Content-Disposition"] = "inline" self._message.attach(report) if self._attach_logfile and self._logfile: try: lfd = open(self._logfile, "rb").read() except: pass # non-fatal else: logmsg = ezmail.MIMEText.MIMEText(lfd, charset=chardet.detect(lfd)) logmsg["Content-Disposition"] = 'attachment; filename=%s' % ( os.path.basename(self._logfile), ) self._message.attach(logmsg) ezmail.mail(self._message)
def finalize(self): """finalizing this Report sends off the email.""" self.write(self._formatter.finalize()) report = ezmail.MIMEText.MIMEText( self._fo.getvalue(), self._formatter.MIMETYPE.split("/")[1]) report["Content-Disposition"] = "inline" self._message.attach(report) if self._attach_logfile and self._logfile: try: lfd = open(self._logfile, "rb").read() except: pass # non-fatal else: logmsg = ezmail.MIMEText.MIMEText(lfd, charset=chardet.detect(lfd)) logmsg["Content-Disposition"] = 'attachment; filename=%s' % ( os.path.basename(self._logfile), ) self._message.attach(logmsg) ezmail.mail(self._message)
def finalize(self): """finalizing this Report sends off the email.""" self.write(self._formatter.finalize()) report = ezmail.MIMEText.MIMEText( self._fo.getvalue(), self._formatter.MIMETYPE.split("/")[1]) report["Content-Disposition"] = "inline" self._message.attach(report) if self._logfile: try: lfd = open(self._logfile).read() except: pass # non-fatal print >> sys.stderr, "could not read or attach log file: %r" % ( self._logfile, ) else: logmsg = ezmail.MIMEText.MIMEText(lfd) logmsg["Content-Disposition"] = 'attachment; filename=%s' % ( os.path.basename(self._logfile), ) self._message.attach(logmsg) ezmail.mail(self._message)
def mailmessage(cp): parts = [] # main message text and subject line body = CF.mail.body(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) parts.append(body) subj = CF.mail.Subject(line=CF.lines.get(cp._device), caller_id=cp.caller_id, caller_name=cp.caller_name) # ogg file attachment oggfile = tempfile.NamedTemporaryFile(suffix=".ogg", prefix="voicemail", dir="/var/tmp") Vgetty.rmd2ogg(cp.inname, oggfile.name) oggfile.seek(0) ogg = ezmail.MIMEApplication.MIMEApplication(oggfile.read(), "ogg") ogg["Content-Disposition"] = "attachment; filename=%s" % (os.path.basename( cp.inname.replace("rmd", "ogg")), ) oggfile.close() parts.append(ogg) # mail it! ezmail.mail(parts, subject=subj, To=CF.mail.To)
def __call__(self, timestamp, ip, community, pdu): tr = traps.TrapRecord(timestamp, ip, community, pdu) ezmail.mail(str(tr), To=self._recipients, From=self._from, subject="Trap from %r" % (str(ip),)) return False