def create_user(username, first_name, last_name, email, affiliation, language, role): """ This function creates an user with the given properties. Moreover: it generates a passwords and emails it to the new user. Raises: smtplib.SMTPException, django.db.utils.DatabaseError """ password = toolkit.random_alphanum(7) log.info("Creating new user: {username}".format(**locals())) u = _create_user(username, first_name, last_name, email, affiliation, language, role, password=password) log.info("Created new user, sending email...") html = render(get_request(), "welcome_email.html", locals()).content text = render(get_request(), "welcome_email.txt", locals()).content sendmail.sendmail(settings.DEFAULT_FROM_EMAIL, email, 'Welcome to AmCAT!', html, text) log.info("Email sent, done!") return u
def send_mail(self, result): table = self.make_table(result).output(rownames = True) n = sum([r['count'] for r in result]) succesful = sum([r['success'] for r in result]) total = len(result) datestr = toolkit.writeDate(self.options['date']) subject = "Daily scraping for {datestr}: {n} articles, {succesful} out of {total} scrapers succesful".format(**locals()) _date = self.options['date'] content = MAIL_ASCII.format(**locals()) for addr in self.options['mail_to'].split(","): sendmail.sendmail("*****@*****.**", addr, subject, None, content)
def send_email(count, messages): counts = [(s.__class__.__name__, n) for (s,n) in count.items()] n = sum(count.values()) counts.append(("Total", n)) t = ListTable(counts, colnames=["Scraper", "#Articles"]) counts_ascii = t.output(useunicode=False, box=False) counts_html = table2html(t, printRowNames=False) succesful = len([1 for (s,n2) in count.items() if n2>0]) total = len(count.items()) datestr = toolkit.writeDate(date.today()) mail_ascii = MAIL_ASCII.format(table=counts_ascii, **locals()) mail_html = MAIL_HTML.format(table=counts_html, **locals()) subject = "Daily scraping for {datestr}: {n} articles, {succesful} out of {total} scrapers succesful".format(**locals()) sendmail.sendmail("*****@*****.**", EMAIL, subject, mail_html, mail_ascii)
def create_user(username, first_name, last_name, email, password=None): """ This function creates an user with the given properties. Moreover: it generates a passwords and emails it to the new user. Raises: smtplib.SMTPException, django.db.utils.DatabaseError """ email_password = (password is None) if password is None: password = toolkit.random_alphanum(7) log.info("Creating new user: {username}".format(**locals())) u = _create_user(username, first_name, last_name, email, password=password) log.info("Created new user, sending email...") html = render(get_request(), "welcome_email.html", locals()).content text = render(get_request(), "welcome_email.txt", locals()).content sendmail.sendmail(settings.DEFAULT_FROM_EMAIL, email, 'Welcome to AmCAT!', html, text) log.info("Email sent, done!") return u