def send_email_template(subject, template, recipients, sender, context=None, cc=None, html=True, silent=False): """ Return task to send an email using the template provided """ body = render_to_string(template, context=Context(context)) args = (subject, body, recipients, sender) kwargs = {"cc": cc, "fail_silently": silent, "html": html} return send_email_task.si(*args, **kwargs)
def email_admin(subject, body, sender): """ Send a basic email to the admins. """ celery_task = send_email.si( subject, body, from_email=sender, to=[email_address_str(name, email) for name, email in settings.ADMINS] ) celery_task.delay() return True
def email_support(subject, body, request): """ Send a basic email to support. """ user, user_email, user_name = lookup_user(request) celery_task = send_email.si( subject, body, from_email=email_address_str(user_name, user_email), to=[email_address_str(*settings.ATMO_SUPPORT)] ) celery_task.delay() return True
def email_from_admin(username, subject, message, html=False): """ Use user, subject and message to build and send a standard Atmosphere admin email from admins to a user. Returns True on success and False on failure. """ from_name, from_email = admin_address() user_email = lookupEmail(username) if not user_email: user_email = "%s@%s" % (username, settings.DEFAULT_EMAIL_DOMAIN) celery_task = send_email.si(subject, message, from_email=email_address_str(from_name, from_email), to=[email_address_str(username, user_email)], cc=[email_address_str(from_name, from_email)], html=html) celery_task.delay() # Task executes here return True
def email_from_admin(username, subject, body, html=False): """ Use user, subject and body to build and send a standard Atmosphere admin email from admins to a user. Returns True on success and False on failure. """ user_email, user_name = user_email_info(username)[1:] sender = email_address_str(*settings.ATMO_DAEMON) celery_task = send_email.si( subject, body, from_email=sender, to=[email_address_str(user_name, user_email)], cc=[sender], html=html ) celery_task.delay() # Task executes here return True
def email_to_admin(subject, body, username=None, user_email=None, cc_user=True, admin_user=None, request_tracker=False, html=False): """ Send a basic email to the admins. Nothing more than subject and message are required. """ if admin_user: sendto, sendto_email = admin_address(admin_user) elif request_tracker: sendto, sendto_email = request_tracker_address() else: sendto, sendto_email = admin_address() # E-mail yourself if no users are provided if not username and not user_email: username, user_email = sendto, sendto_email elif not user_email: # Username provided # TODO: Pass only strings, avoid passing 'User' object here. if isinstance(username, User): username = username.username user_email = lookupEmail(username) if not user_email: user_email = "%s@%s" % (username, settings.DEFAULT_EMAIL_DOMAIN) elif not username: # user_email provided username = '******' if request_tracker or not cc_user: # Send w/o the CC cc = [] else: cc = [email_address_str(username, user_email)] celery_task = send_email.si(subject, body, from_email=email_address_str( username, user_email), to=[email_address_str(sendto, sendto_email)], cc=cc, html=html) celery_task.delay() # Task executes here return True
def email_to_admin( subject, body, username=None, user_email=None, cc_user=True, admin_user=None, request_tracker=False, html=False): """ Send a basic email to the admins. Nothing more than subject and message are required. """ if admin_user: sendto, sendto_email = admin_address(admin_user) elif request_tracker: sendto, sendto_email = request_tracker_address() else: sendto, sendto_email = admin_address() # E-mail yourself if no users are provided if not username and not user_email: username, user_email = sendto, sendto_email elif not user_email: # Username provided # TODO: Pass only strings, avoid passing 'User' object here. if isinstance(username, User): username = username.username user_email = lookupEmail(username) if not user_email: user_email = "%s@%s" % (username, settings.DEFAULT_EMAIL_DOMAIN) elif not username: # user_email provided username = '******' if request_tracker or not cc_user: # Send w/o the CC cc = [] else: cc = [email_address_str(username, user_email)] celery_task = send_email.si(subject, body, from_email=email_address_str(username, user_email), to=[email_address_str(sendto, sendto_email)], cc=cc, html=html) celery_task.delay() # Task executes here return True