def email(self, email: "List or not", cc=None, bcc=None): """ USE THE Email API TO SEND AN EMAIL HANDLES IT WHETHER OR NOT LISTS ARE PASSED """ e = Email(self.server) e.define_sender(self.sender) if isinstance(email, list): for item in email: e.add_to(item) else: e.add_to(email) if cc: if isinstance(cc, list): for item in cc: e.add_cc(item) else: e.add_cc(cc) if bcc: if isinstance(bcc, list): for item in bcc: e.add_bcc(item) else: e.add_bcc(bcc) e.define_subject(self.get_subject()) e.define_content(self.get_html()) try: e.send() except smtplib.SMTPRecipientsRefused: self.print_email(email)
where = line.index(search_item) message = line[ (where+ len(search_item)+1): -1] match = re.search("orig_to=<(.*?)>", line) if match: orig_to = match.group(1) if args.stdout: print(to_who) print(orig_to) bounce = bounces[to_who] bounce.key = escape(to_who) bounce.count += 1 bounce.messages.append(escape(message)) email = Email(domain) email.add_to('*****@*****.**') email.make_subject("Bounces") email.define_sender('DragonNet Admin <*****@*****.**>') html = "<html>" for bounce in bounces: ns = NS(bounces[bounce]) ns.messages = "<br />".join(ns.messages) ns.BR = '<br />' html += ns('<p>Email{COLON}{SPACE}{key}{SPACE} ' \ 'How many bounces{COLON}{SPACE}{count}{BR}<i>{messages}</i></p>') html+= "</html>" email.define_content(html) if not args.no_emails: email.send() if args.stdout: print(email.htmls['en'])