def send_found_notify(notify): context = { 'query': notify.task.query, 'query_opt': notify.task.query_opt, 'query_title': notify.task.query_title, 'decl_list': load_declarations(notify.new_ids), 'found_new': notify.found_new, 'site_url': settings.SITE_URL, } if notify.email and notify.email.endswith('.chatbot'): from chatbot.utils import send_to_chat # need save before use to obtain notify.id notify.save() return send_to_chat(notify, context) if notify.email and notify.email.endswith('.broadcast'): from chatbot.utils import send_to_channels notify.save() return send_to_channels(notify, context) # send notify to regular email from_email = settings.FROM_EMAIL subject = render_to_string("email_found_subject.txt", context).strip() message = render_to_string("email_found_message.txt", context) msghtml = render_to_string("email_found_message.html", context) try: notify.error = send_mail(subject, message, from_email, [notify.email], html_message=msghtml) or 'unknown result' except Exception as e: logger.error("send_mail %s failed with error: %s", notify.email, e) notify.error = str(e) return notify.error
def send_newtask_notify(task): context = { 'query': task.query, 'site_url': settings.EMAIL_SITE_URL, } from_email = settings.FROM_EMAIL subject = render_to_string("email_newtask_subject.txt", context).strip() message = render_to_string("email_newtask_message.txt", context) msghtml = render_to_string("email_newtask_message.html", context) try: res = send_mail(subject, message, from_email, [task.user.email], html_message=msghtml) except Exception as e: logger.error("send_mail %s failed with error: %s", task.user.email, e) res = False return bool(res)
def send_login_temporary_link(user_id, email): context = { 'link': get_login_temporary_link(user_id, email), 'site_url': settings.EMAIL_SITE_URL, } from_email = settings.FROM_EMAIL subject = render_to_string("email_login_subject.txt", context).strip() message = render_to_string("email_login_message.txt", context) msghtml = render_to_string("email_login_message.html", context) try: endtime = datetime.now() + timedelta(minutes=15) subject += " " + endtime.strftime("%H:%M") res = send_mail(subject, message, from_email, [email], html_message=msghtml) except Exception as e: logger.error("send_mail %s failed with error: %s", email, e) res = False return bool(res)
def send_found_notify(notify): context = { 'query': notify.task.query, 'decl_list': load_declarations(notify.new_ids), 'found_new': notify.found_new, 'site_url': settings.EMAIL_SITE_URL, } from_email = settings.FROM_EMAIL subject = render_to_string("email_found_subject.txt", context).strip() message = render_to_string("email_found_message.txt", context) msghtml = render_to_string("email_found_message.html", context) try: notify.error = send_mail(subject, message, from_email, [notify.email], html_message=msghtml) except Exception as e: logger.error("send_mail %s failed with error: %s", notify.email, e) notify.error = str(e) return notify.error
def send_confirm_email(request, email): args = { 'email': email, 'time': time(), } args['mac'] = get_verification_hmac(request.user, **args) context = { 'email': email, 'link': reverse_qs('confirm_email', args), 'site_url': settings.EMAIL_SITE_URL, } from_email = settings.FROM_EMAIL subject = render_to_string("email_confirm_subject.txt", context).strip() message = render_to_string("email_confirm_message.txt", context) msghtml = render_to_string("email_confirm_message.html", context) try: res = send_mail(subject, message, from_email, [email], html_message=msghtml) except Exception as e: logger.error("send_mail %s failed with error: %s", email, e) res = False return bool(res)