def send_with_template(prefix, parm): """ Send an email using template """ parm['from'] = cfg.email_from() parm['date'] = get_email_date() lst = [] path = cfg.email_dir.get_path() if path and os.path.exists(path): try: lst = glob.glob(os.path.join(path, '%s-*.tmpl' % prefix)) except: logging.error(Ta('Cannot find email templates in %s'), path) else: path = os.path.join(sabnzbd.DIR_PROG, DEF_EMAIL_TMPL) tpath = os.path.join(path, '%s-%s.tmpl' % (prefix, cfg.language())) if os.path.exists(tpath): lst = [tpath] else: lst = [os.path.join(path, '%s-en.tmpl' % prefix)] sent = False for temp in lst: if os.access(temp, os.R_OK): source = _decode_file(temp) if source: sent = True if len(cfg.email_to()): for recipient in cfg.email_to(): parm['to'] = recipient message = Template(source=source, searchList=[parm], filter=EmailFilter, compilerSettings={ 'directiveStartToken': '<!--#', 'directiveEndToken': '#-->' }) ret = send(message.respond(), recipient) del message else: ret = T('No recipients given, no email sent') else: ret = T('Invalid encoding of email template %s') % temp errormsg(ret) if not sent: ret = T('No email templates found') errormsg(ret) return ret
def send_with_template(prefix, parm): """ Send an email using template """ parm['from'] = cfg.email_from() parm['date'] = get_email_date() lst = [] path = cfg.email_dir.get_path() if path and os.path.exists(path): try: lst = glob.glob(os.path.join(path, '%s-*.tmpl' % prefix)) except: logging.error(Ta('Cannot find email templates in %s'), path) else: path = os.path.join(sabnzbd.DIR_PROG, DEF_EMAIL_TMPL) tpath = os.path.join(path, '%s-%s.tmpl' % (prefix, cfg.language())) if os.path.exists(tpath): lst = [tpath] else: lst = [os.path.join(path, '%s-en.tmpl' % prefix)] sent = False for temp in lst: if os.access(temp, os.R_OK): source = _decode_file(temp) if source: sent = True if len(cfg.email_to()): for recipient in cfg.email_to(): parm['to'] = recipient message = Template(source=source, searchList=[parm], filter=EmailFilter, compilerSettings={'directiveStartToken': '<!--#', 'directiveEndToken': '#-->'}) ret = send(message.respond(), recipient) del message else: ret = T('No recipients given, no email sent') else: ret = T('Invalid encoding of email template %s') % temp errormsg(ret) if not sent: ret = T('No email templates found') errormsg(ret) return ret
def send_with_template(prefix, parm, test=None): """ Send an email using template """ parm["from"] = cfg.email_from() parm["date"] = get_email_date() ret = None email_templates = [] path = cfg.email_dir.get_path() if path and os.path.exists(path): try: email_templates = glob.glob( os.path.join(path, "%s-*.tmpl" % prefix)) except: logging.error(T("Cannot find email templates in %s"), path) else: path = os.path.join(sabnzbd.DIR_PROG, DEF_EMAIL_TMPL) tpath = os.path.join(path, "%s-%s.tmpl" % (prefix, cfg.language())) if os.path.exists(tpath): email_templates = [tpath] else: email_templates = [os.path.join(path, "%s-en.tmpl" % prefix)] for template_file in email_templates: logging.debug("Trying to send email using template %s", template_file) if os.access(template_file, os.R_OK): if test: recipients = [test.get("email_to")] else: recipients = cfg.email_to() if len(recipients): for recipient in recipients: # Force-open as UTF-8, otherwise Cheetah breaks it with open(template_file, "r", encoding="utf-8") as template_fp: parm["to"] = recipient message = Template(file=template_fp, searchList=[parm], compilerSettings=CHEETAH_DIRECTIVES) ret = send_email(message.respond(), recipient, test) else: ret = T("No recipients given, no email sent") else: # Can't open or read file, stop return errormsg(T("Cannot read %s") % template_file) # Did we send any emails at all? if not ret: ret = T("No email templates found") return ret
def diskfull(): """ Send email about disk full, no templates """ if cfg.email_full(): return send(T('''To: %s From: %s Date: %s Subject: SABnzbd reports Disk Full Hi, SABnzbd has stopped downloading, because the disk is almost full. Please make room and resume SABnzbd manually. ''') % (cfg.email_to.get_string(), cfg.email_from(), get_email_date()), cfg.email_to()) else: return ""