Пример #1
0
def send_reg_confirm_mail(recipient, token):
    """
    token as string decoded to utf-8
    """
    link = create_link(request.url_root, 'auth.confirm_registration', token)

    msg = Message(
        subject='Spending Tracker - Activate your registration',
        recipients=[recipient],
        # !Don't add href attr to the link,
        # because e.g. gmail redirects to it through www.google.hu?q=<link>
        html=("<header>"
              "<h3>Spending Tracker - Activate your registration</h3>"
              "<p>You received this email "
              "because you had signed up for Spending Tracker.</p>"
              "</header>"
              "<main>"
              "<p>Copy this link</p>"
              "<hr>"
              "<em><a>%s</a></em>"
              "<hr>"
              "<p>to the URL bar and hit enter"
              " to activate your registration.</p>"
              "</main>"
              "<footer>"
              "<p><small>If you haven't registered at Spending Tracker, "
              "ignore this email and feel free to remove it. "
              "We're sorry to bother you :)</small></p>"
              "</footer>") % link)
    mail.send(msg)
Пример #2
0
def send_reset_password_mail(user_email, request):

    user = User().load({'email': user_email})
    if user.id:
        msg = Message()
        msg.add_recipient(user_email)
        minutes = 30
        token = User.encode_auth_token(user.id,
                                       days=0,
                                       seconds=0,
                                       minutes=minutes).decode()
        link = f'http://{request.host}/reset/{token}'
        msg.html = get_reset_password_html(
            username=f"{user.first_name} {user.last_name}",
            link=link,
            minutes=minutes,
            token=token)
        msg.subject = 'Reset Password Request'
        msg.sender = '*****@*****.**'
        mail.send(msg)

        response_object = {
            'status': 'success',
            'message': 'An email with a reset was sent link.',
        }
        return response_object, 200

    else:
        response_object = {
            'status': 'fail',
            'message': 'User provided email does not exist.',
        }
        return response_object, 409
Пример #3
0
def send_cancel_reg_confirm_email(recipient, token):
    link = create_link(request.url_root, 'auth.confirm_cancel_registration',
                       token)

    msg = Message(
        subject=('Spending Tracker - Confirm cancellation of your Spending'
                 'Tracker account.'),
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Confirm cancellation "
              "of your Spending Tracker account.</h3>"
              "</header>"
              "<main>"
              "<p>You received this email because you had initiated "
              "the cancellation of your Spending Tracker account.</p>"
              "<p>Copy this link</p>"
              "<hr>"
              "<em><a>%s</a></em>"
              "<hr>"
              "<p>to the URL bar and hit enter to confirm your cancellation. "
              "<b>This will delete your account permanently!</b></p>"
              "<p>Sorry to see you go :(</p>"
              "</main>"
              "<footer>"
              "<small>"
              "<p>If you've received this email and haven't initiated "
              "the cancellation of your Spending Tracker account, "
              "change your Spending Tracker password as soon as possible!</p>"
              "</small>"
              "</footer>") % link)
    mail.send(msg)
Пример #4
0
def daily_messenger(orders: list):
    msg = Message(datetime.now().strftime("%Y-%M-%D Messenger"), recipients=["*****@*****.**"])
    msg.html = '<table><tbody><tr><th>姓名</th><th>Asin</th><th>订单号</th><th>状态</th><th>价格</th><th>PayPal</th></tr>' + \
               ''.join(map(lambda x: '<tr><td>' + '</td><td>'.join(map(lambda k: str(k), x)) + '</td></tr>', orders)) + \
               '</tbody></table>'
    current_app.logger.info('邮件发送 %s', msg.html)
    mail.send(msg)
Пример #5
0
def send_password_reset_mail(user):
    sender = '*****@*****.**'
    serializer = URLSafeSerializer('reset_salt')
    token = serializer.dumps(user.id)
    msg = Message('Password reset', sender=sender, recipients=[user.email])
    msg.body = f'Password reset link: {FINNPLUS_DOMAIN}/reset/{token}'
    print(f'{FINNPLUS_DOMAIN}/resetpw/{token}')
    mail.send(msg)
    return 'Email sent'
Пример #6
0
def send_confirm_email(user):
    sender = '*****@*****.**'
    msg = Message('Confirmation email', sender=sender, recipients=[user.email])
    serializer = URLSafeSerializer('verification_salt')
    token = serializer.dumps(user.id)
    msg.body = f'Confirmation link: {FINNPLUS_DOMAIN}/activate/{token}'
    print(f'{FINNPLUS_DOMAIN}/activate/{token}')
    mail.send(msg)
    return 'Email sent'
Пример #7
0
def send_password_reset_mail(user):
    sender = '*****@*****.**'  #'*****@*****.**'
    serializer = URLSafeSerializer('reset_salt')
    token = serializer.dumps(user.id)
    msg = Message('Password reset', sender=sender, recipients=[user.email])
    msg.body = f'Password reset link: {FINNPLUS_DOMAIN}/reset/{token}'
    msg.html = f'<h3>Finnplus password reset link:</h3> <a href={FINNPLUS_DOMAIN}/reset/{token}>Reset your password by clicking this link</a>'
    print(f'{FINNPLUS_DOMAIN}/reset/{token}')
    mail.send(msg)
    return 'Email sent'
Пример #8
0
def send_confirm_email(user):
    # TODO: merge with password reset email
    sender = '*****@*****.**'  #'*****@*****.**'
    msg = Message('Confirmation email', sender=sender, recipients=[user.email])
    serializer = URLSafeSerializer('verification_salt')
    token = serializer.dumps(user.id)
    msg.body = f'Finnplus account confirmation link: {FINNPLUS_DOMAIN}/activate/{token}'
    msg.html = f'<h3>Finnplus account confirmation link:</h3> <a href={FINNPLUS_DOMAIN}/activate/{token}>Activate your finnplus account here</a>'
    print(f'{FINNPLUS_DOMAIN}/activate/{token}')
    mail.send(msg)
    return 'Email sent'
Пример #9
0
def send_new_password_mail(recipient, new_password):
    msg = Message(
        subject='Spending Tracker - Reset password',
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Reset password</h3>"
              "<p>You received this email "
              "because you had requested a new password "
              "for your Spending Tracker account.</p>"
              "</header>"
              "<main>"
              "<p>Your new password:</p>"
              "<hr>"
              "<em>%s</em>"
              "<hr>"
              "<p><strong>We recommend that you change your password "
              "next time you log in.</strong></p>"
              "<footer>"
              "</footer>") % new_password)
    mail.send(msg)
Пример #10
0
def send_cancel_reg_confirmed_email(recipient):
    msg = Message(
        subject='Spending Tracker - Account cancelled.',
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Account cancelled.</h3>"
              "</header>"
              "<main>"
              "<p>Your Spending Tracker account has been cancelled.</p>"
              "<p>Sorry to see you go :(</p>"
              "</main>"
              "<footer>"
              "<small>"
              "<p>If you haven't initiated the cancellation process, "
              "change your password as soon as possible!</p>"
              "<p>Unfortunately, we cannot restore your account "
              "as the cancellation's effect is permanent "
              "but you are more than welcome to sign up again.</p>"
              "</small>"
              "</footer>"))
    mail.send(msg)
Пример #11
0
def send_statistics_export_mail(recipient, attachments):
    msg = Message(
        subject="Spending Tracker - Statistics Exported",
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Statistics Exported</h3>"
              "</header>"
              "<main>"
              "<p>Statistics Exported</p>"
              "</main>"
              "<footer>"
              "<small>"
              "<p>If you've received this email and haven't initiated the "
              "exportation of your statistics, "
              "change your Spending Tracker password as soon as possible!</p>"
              "</small>"
              "</footer>"))
    for attachment in attachments:
        msg.attach(filename=attachment['filename'],
                   content_type=attachment['content_type'],
                   data=attachment['data'])
    mail.send(msg)
Пример #12
0
def send_reg_confirmed_mail(recipient):
    msg = Message(
        subject='Spending Tracker - Registration activated',
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Registration activated</h3>"
              "</header>"
              "<main>"
              "<p>Your registration for Spending Tracker has been activated. "
              "Enjoy! ;)</p>"
              "</main>"
              "<footer>"
              "<small>"
              "<p>"
              "If you haven't registered at Spending Tracker, please contact "
              '<a href="mailto:{}?Subject=Unwanted%20Registration&'
              "body=Hello%20Johnny!\n\nI%20have%20not%20registered%20at%20"
              'Spending%20Tracker.\n\nPlease%20remove%20my%20account!"'
              '>me</a> and change your password as soon as possible!'
              "</p>"
              "</small>"
              "</footer>").format(app.config['MAIL_DEFAULT_SENDER']))
    mail.send(msg)
Пример #13
0
def send_reset_password_mail(recipient, token):
    link = create_link(request.url_root, 'auth.reset_password', token)
    msg = Message(
        subject='Spending Tracker - Forgot password',
        recipients=[recipient],
        html=("<header>"
              "<h3>Spending Tracker - Forgot password</h3>"
              "<p>You received this email "
              "because you had requested a link to reset your password "
              "for your Spending Tracker account.</p>"
              "</header>"
              "<main>"
              "<p>Copy this link</p>"
              "<hr>"
              "<em><a>%s</a></em>"
              "<hr>"
              "<p>to the URL bar and hit enter to request a new password.</p>"
              "</main>"
              "<footer>"
              "<p><small>If you haven't requested a new password, "
              "ignore this email and feel free to remove it. "
              "We're sorry to bother you :)</small></p>"
              "</footer>") % link)
    mail.send(msg)
Пример #14
0
def send_async_email(app, msg):
    with app.app.app_context():
        mail.send(msg)