def notify_staff_about_signup(user): recipients = app.config['NEW_GSE_SIGNUP_EMAIL_LIST'] if not recipients: return msg = Message(subject="New customer signs up for GSE", sender=_get_sender(), recipients=recipients) msg.html = render_template( "gse_signup/emails/staff_notification.html", user=user, host_url=request.host_url, ) send_mail(msg, email_description="Staff notification about GSE signup")
def gse_signup_confirm(): token = request.args.get("validation_token") if not token: return jsonify(ok=False, error="Validation token is required.") vt = ValidationToken.objects.find_one(digest=token) if not (vt and vt.is_valid): return jsonify(ok=False, error="Validation token is invalid.") user = vt.creator user_data = { "first_name": user.first_name, "last_name": user.last_name, "email": user.email, "company_name": user.account.name, } session['user'] = user_data if request.method == "GET": return render_template("gse_signup/signup.html", show_password=True, user_json=json.dumps(user_data)) elif request.method == "POST": data = request.json password = data["password"] # I guess, changing other fields is not in the spec, so just set password here user.set_password(password) # send email saying login has been completed msg = Message( subject="Your Genesys Social Engagement login has been completed", sender=_get_sender(), recipients=[user.email]) msg.html = render_template( "gse_signup/emails/after_successful_signup.html", user=user, host_url=request.host_url, ) try: send_mail(msg, email_description="GSE signup successful email") except Exception, err: app.logger.exception( "send_mail failed after successful GSE signup") # expire validation token vt.consume() return jsonify(ok=True, redirect_url=url_for("gse_signup_success"))
def send_invitation_email(user, validation_token, full_name): """ First invitation email once a new trial has been created by staff member. """ msg = Message(subject="Twitter Channel Sign-up - Genesys Social Analytics", sender=_get_sender(), recipients=[user.email]) msg.html = render_template("mail/invitation_email.html", full_name=full_name, url=validation_token.signup_url) # LOGGER.debug(msg.body) if get_app_mode() != 'dev': send_mail(msg, email_description='invitation email') else: LOGGER.info(msg.html)
def send_validation_email(user, channel): """ Sends validation email once successfully configured a twitter channel through the signup wizzard. """ msg = Message( subject="Twitter Channel Confirmation - Genesys Social Analytics", sender=_get_sender(), recipients=[user.email]) msg.html = render_template("mail/validation_email.html", channel_name=channel.title, url=get_var('HOST_DOMAIN')) # LOGGER.debug(msg.body) if get_app_mode() != 'dev': send_mail(msg, email_description='channel confirmation email') else: LOGGER.info(msg.html)
def send_new_channel_creation(staff_user, admin_user, channel, link): """ Send warning email to a user once a user with a trial account creates a new channel """ msg = Message( subject="A channel has been created for a trial account you created", sender=_get_sender(), recipients=[staff_user.email] + get_var('ONBOARDING_ADMIN_LIST')) handles = channel.usernames thandle = 'Unknown' for handle in handles: if handle.startswith('@'): thandle = handle # Get the sender name staff_user_name = 'Unknown' admin_user_name = 'Unknown' admin_email = 'Unknown' ckeywords = 'None defined yet' cskipwords = 'None defined yet' if staff_user.first_name is not None: staff_user_name = staff_user.first_name if admin_user.first_name is not None: admin_user_name = admin_user.first_name if admin_user.email is not None: admin_email = admin_user.email if channel.keywords: ckeywords = '' for keyword in channel.keywords: ckeywords += keyword + ' ' if channel.skipwords: cskipwords = '' for skipword in channel.skipwords: cskipwords += skipword + ' ' msg.html = render_template("mail/new_channel_creation.html", staff_user_name=staff_user_name, admin_user_name=admin_user_name, admin_user_email=admin_email, keywords=ckeywords, skipwords=cskipwords, twitter_handle=thandle, channel_link=link) if get_app_mode() != 'dev': send_mail(msg, email_description='new channel confirmation email') else: LOGGER.info(msg.html)
def send_account_posts_daily_limit_warning( recipients, account_name, limit, template='mail/daily_limit_reached.html'): for (email, first_name) in recipients: msg = Message( subject= "Daily limit of {} posts reached. Genesys Social Analytics Notification." .format(limit), sender=_get_sender(), recipients=[email]) msg.html = render_template(template, user_name=first_name or 'Admin', limit=limit, account_name=account_name) send_mail(msg)
def error_notifier_500(subject, raised_exception, system_info=None): if get_app_mode() == 'prod': recipients = get_var('DEV_ADMIN_LIST') if not recipients: return msg = Message(subject=subject) msg.recipients = recipients msg.html = render_template("error_pages/500_email_notification.html", error_message=raised_exception, system_info=system_info) try: send_mail(msg) except EmailSendError: pass else: LOGGER.error("Got unhandled exception:") LOGGER.error(raised_exception) LOGGER.error("System info when it was raised:") LOGGER.error(system_info)
def send_confimation_email(user, on_boarded_customer, keywods, usernames, skipwords): """ Send confirmation email to a user once signup process is completed """ msg = Message( subject="Customer just signed up! - Genesys Social Analytics", sender=_get_sender(), recipients=[user.email] + get_var('ONBOARDING_ADMIN_LIST')) msg.html = render_template("mail/confirmation_email.html", user_name=user.first_name, customer_email=on_boarded_customer.email, keywords=keywods, usernames=usernames, skipwords=skipwords) if get_app_mode() != 'dev': send_mail(msg, email_description='signup notification email') else: LOGGER.info(msg.html)
def send_account_posts_limit_warning(user, percentage, volume): """ Sends a warning message to the Account admin when the posts limit for that account has reached a percentage :param user: The admin user or users :param percentage: The percentage surpassed :param volume: The volume allowed for this account """ msg = Message(subject="Genesys Social Analytics Notification, " + percentage + " of Permitted Traffic Volume Reached", sender=_get_sender(), recipients=[user.email]) msg.html = render_template("mail/threshold_warning.html", user_name=user.first_name or "Admin", percentage=percentage, volume=volume) if get_app_mode() != 'dev': send_mail(msg) else: LOGGER.info(msg.html)
def send_user_create_notification(user): """ Sends a notification to recently created user with a url of the app and a url to reset his password. :param user: The recently create user """ url = user.signed_password_url() app_url = get_var('HOST_DOMAIN') msg = Message(subject="Your Genesys Social Analytics Login Has Been Setup", sender=_get_sender(), recipients=[user.email]) msg.html = render_template("mail/user_creation_email.html", url=url, app_url=app_url) # LOGGER.debug(msg.body) if get_app_mode() != 'dev': send_mail(msg, email_description='email notification to the created user') else: LOGGER.info(msg.html)
def send_tag_alert_emails(tag): """ Sends emails to every tag.alert_email :param tag SmartTagChannel: :returns: True if sending process was successful, False otherwise """ if not tag.alert_can_be_sent: return False # to prevent sending several emails by different processes # we sent alert_last_sent_at to current time # it is changed back if sending was unsuccesful previous_sent_time = tag.alert_last_sent_at tag.alert_last_sent_at = datetime.now() tag.save() # noinspection PyBroadException try: tag_edit_url = '{}/configure#/tags/edit/{}'.format( get_var('HOST_DOMAIN'), str(tag.id)) for user_email in tag.alert_emails: s = URLSafeSerializer(get_var('UNSUBSCRIBE_KEY'), get_var('UNSUBSCRIBE_SALT')) email_tag_id = s.dumps((user_email, str(tag.id))) tag_unsubscribe_url = '{}/unsubscribe/tag/{}'.format( get_var('HOST_DOMAIN'), email_tag_id) tag_view_url = '{}/inbound#?tag={}&channel={}'.format( get_var('HOST_DOMAIN'), str(tag.id), str(tag.parent_channel)) msg = Message(subject="Geneys Social Analytics Alert - Smart Tag", sender=_get_sender(), recipients=[user_email]) try: user = User.objects.get(email=user_email) except User.DoesNotExist: user = None msg.html = render_template( "mail/smarttag_alert.html", user_name=user.first_name if user else None, tag_title=tag.title, tag_edit_url=tag_edit_url, tag_unsubscribe_url=tag_unsubscribe_url, tag_view_url=tag_view_url) # get_var('ON_TEST') since when running tests # get_app_mode() returns 'dev' in pool_worker thread try: app_mode = get_app_mode() except RuntimeError: app_mode = 'dev' if app_mode != 'dev' or get_var('ON_TEST'): send_mail(msg) else: LOGGER.info(msg.html) tag.alert_last_sent_at = datetime.now() tag.save() return True except: if previous_sent_time: tag.alert_last_sent_at = previous_sent_time tag.save() return False
def gse_signup(): if request.method == "GET": return render_template("gse_signup/signup.html") elif request.method == "POST": data = request.json first_name = data["first_name"].strip() last_name = data["last_name"].strip() email = data["email"].strip() company_name = data["company_name"].strip() if len(company_name) > 30: return jsonify( ok=False, error="Company name must not be greater than 30 chars long " "(%d chars given)" % len(company_name)) account_created = False user_created = False token_created = False try: account = Account.objects.find_one(name=company_name) if account is None: account = Account.objects.create( name=company_name, available_apps={APP_GSE: CONFIGURABLE_APPS[APP_GSE]}, created_at=now(), ) account.selected_app = APP_GSE account_created = True else: return jsonify( ok=False, error="Company name '%s' cannot be used because account " "with the same name already exists." % company_name) # create user but don't activate it yet # by setting random password behind the scene try: user = User.objects.create( first_name=first_name, last_name=last_name, email=email, account=account, user_roles=[ADMIN], ) user_created = True except AppException: raise Exception("Sorry, this email is already registered.") token = ValidationToken.objects.create_by_user(user) token_created = True verification_link = url_for("gse_signup_confirm", validation_token=token.digest, _external=True) # send verification email msg = Message( subject= "Confirmation required for Genesys Social Engagement deployment", sender=_get_sender(), recipients=[user.email]) msg.html = render_template( "gse_signup/emails/verification.html", user=user, verification_link=verification_link, ) try: send_mail(msg, email_description="GSE signup verification email") except Exception, err: app.logger.exception( "send_mail failed for GSE signup verification email") raise Exception( "Sorry, we failed to send email to '%s' (%s). Please contact customer support to complete your account provisioning." % (user.email, err)) notify_staff_about_signup(user) except Exception, err: #app.logger.exception('GSE signup failed') if account_created: account.delete() if user_created: user.delete() if token_created: token.delete() return jsonify(ok=False, error=str(err))