Example #1
0
def SendEmail():
    user_email = request.form['email']

    if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",
                    user_email):
        return {'code': 400, 'msg': '邮箱地址非法'}

    msg = Message('TJ-oj注册邮箱验证码',
                  sender='*****@*****.**',
                  recipients=[user_email])
    code = ''.join(
        random.choice(
            'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
        for _ in range(6))
    msg.body = f'''您的验证码为:{code}
-----------------------------
验证码在10分钟内有效
-----------------------------
'''
    with app.app_context():
        mail.send(msg)
    mails_list[user_email] = (
        code, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    #return redirect(url_for('user.Register'))   #这里register界面填写过的内容可能会清空吧?
    return {'code': '200'}
Example #2
0
def send_contact_email(name, email, message):
    msg = Message('TEMPLATE Contact Form', sender='*****@*****.**', recipients=current_app.config['MAIL_TO'].split()) # cc=[email],
    msg.body = f'''Name: {name}
Email: {email}
Message: {message}
'''
    mail.send(msg)
Example #3
0
def send_account_removed_email(user):
    message = Message("Account Removed | Driving Rewards",
                      sender="*****@*****.**",
                      recipients=[user.email])
    message.body = f"""{user.first_name},
Your account has been removed."""
    mail.send(message)
Example #4
0
def store_and_send_contact_data(post_request):
    with app.app_context():
        post_request.pop('button')
        contact_us_dir = pathlib.Path('./contact-us')
        contact_us_dir.mkdir(exist_ok=True)
        if any(post_request.values()):
            # This is `slightly` risky file naming because if the user makes another POST request
            # within one second of sending there previous one, there will be filenaming conflicts.
            # With the current implementation, the old file will just be overwritten,
            # mainly so that the data is consistent, as opposed to appending the data
            # to the existing file.
            post_data_loc = contact_us_dir / f"{format(datetime.datetime.today(), '%Y-%m-%d_%I.%M.%S.%p')}.json"
            with post_data_loc.open(mode='w') as file:
                json.dump(post_request, file, indent=4)

            # Send an email when someone fill outs the `Contact Us` form
            msg = Message(
                subject=
                f"{post_request['fname']} {post_request['lname']} filled out the Contact Us form!",
                body=(f"First Name: {post_request['fname']}\n"
                      f"Last Name: {post_request['lname']}\n"
                      f"Reason for Contacting: {post_request['reason']}\n"
                      f"Email address: {post_request['eaddress']}"),
                recipients=[dotenv_values()['contact_page_email']])
            mail.send(msg)
Example #5
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request', sender="*****@*****.**", recipients=[user.email])
    msg.body = f'''To reset your password,visit the following link:
    {url_for('reset_token',token=token,_external=True)}
    If you did not make this request then simply ignore this message no changes will occur
    '''
    flash(f'{msg}',success)
    mail.send(msg)
Example #6
0
def send_reset_email(user):
    token = user.get_reset_token()
    message = Message("Password Reset Link | Driving Rewards",
                      sender="*****@*****.**",
                      recipients=[user.email])
    message.body = f"""To reset your Driving Rewards Portal password, follow this link:
{url_for("reset_password", token=token, _external=True)}

If you did not request a password reset, please ignore this email."""
    mail.send(message)
Example #7
0
def send_new_driver_email(sponsorship):
    user = sponsorship.driver
    sponsor = sponsorship.sponsor
    message = Message("New Sponsorship | Driving Rewards",
                      sender="*****@*****.**",
                      recipients=[user.email])
    message.body = f"""{user.first_name},
You were approved for a sponsorship with {sponsor}!
To check out their catalog, visit {url_for("catalog", id=sponsorship.id, _external=True)}"""
    mail.send(message)
Example #8
0
def send_new_points_email(sponsorship):
    user = sponsorship.driver
    sponsor = sponsorship.sponsor
    message = Message("New Rewards Balance | Driving Rewards",
                      sender="*****@*****.**",
                      recipients=[user.email])
    message.body = f"""{user.first_name},
Your new rewards balance with {sponsor} is {sponsorship.points} points.
To check out their catalog, visit {url_for("catalog", id=sponsorship.id, _external=True)}"""
    mail.send(message)
Example #9
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, go to the following link:
{url_for('users.reset_token', token=token, _external=True)}

If you did not make this password reset request, ignore this email.
'''
    mail.send(msg)
Example #10
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, click the link below:
{url_for('users.reset_password', token=token, _external=True)}

If you did not make this request, ignore this message. 
    '''
    mail.send(msg)
Example #11
0
def send_request_email(user):
    token = user.username
    msg = Message('Account Request',
                  sender='*****@*****.**',
                  recipients=["*****@*****.**"])
    ip_url = url_for('users.add_user', token=token, _external=True)
    url = re.sub(ip_addr_regex, website_substitute, ip_url)
    msg.body = f'''Account requested for {user.username}, email: {user.email}.
    Authenticate: {url}
'''
    mail.send(msg)
Example #12
0
def send_set_email(user):
    token = user.get_reset_token()
    msg = Message('Set Password',
                  sender='*****@*****.**',
                  recipients=[user.email])
    ip_url = url_for('users.reset_token', token=token, _external=True)
    url = re.sub(ip_addr_regex, website_substitute, ip_url)
    msg.body = f'''To set your password, visit the following link:{url}
If you did not make this request then simply ignore this email and no changes will be made.
'''
    mail.send(msg)
Example #13
0
def send_order_cancel_email(order):
    sponsorship = order.sponsorship
    user = sponsorship.driver
    sponsor = sponsorship.sponsor
    message = Message(
        f"Your Order from {sponsor} Was Canceled | Driving Rewards",
        sender="*****@*****.**",
        recipients=[user.email])
    message.body = f"""Order #{order.id} from {sponsor} was canceled.
To view your orders, visit {url_for("orders", _external=True)}"""
    mail.send(message)
Example #14
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
{url_for('users.reset_token', token=token, _external=True)}

If you did not make this request then simply ignore this email and no changes will be made.
'''
    mail.send(msg)
Example #15
0
def send_order_summary_email(order, items, subtotal):
    sponsorship = order.sponsorship
    user = sponsorship.driver
    sponsor = sponsorship.sponsor
    table = ItemTable(items)
    table.remove.show = False
    message = Message(f"Your Order from {sponsor} | Driving Rewards",
                      sender="*****@*****.**",
                      recipients=[user.email])
    message.html = render_template("order_info.html",
                                   order=order,
                                   table=table,
                                   subtotal=subtotal)
    mail.send(message)
def forgot_password():
    error = ''
    if request.method == "POST":
        username = request.form["username"]
        user = User.query.filter_by(username=username)
        if user.email is None:
            error = "There is no email associated with your account."
        else:
            msg = Message("Password Reset for Coding for Kidz",
                          sender="*****@*****.**",
                          recipients=[user.email])
            msg.body = "Dear " + user.username + " ,\nYou can reset your password at this link. This link will expire in 24 hours. If you did not request a password reset you can safely ignore the email.\nThanks,\nThe Coding for Kidz team"
            msg.html = "Dear " + user.username + " ,<br><br>You can reset your password here. This link will expire in 24 hours. If you did not request a password reset you can safely ignore the email.<br><br>Thanks,<br><br>The Coding for Kidz team"
            mail.send(msg)
    else:
        return render_template("forgotpassword.html", error=error)
Example #17
0
def send_email(to: str, subject: str, template: str) -> None:
    """
    This will send a email

    :param to: Email recipient
    :param subject: The subject of the email
    :param template: The email html template
    """

    msg = Message(
        subject,
        recipients=[to],
        html=template,
        sender="*****@*****.**"  # TODO: Make this a config
    )
    mail.send(msg)
Example #18
0
def resend_confirmation_link(email):
    user = User.query.filter_by(email=email).first()
    if user.is_validated:
        # Email-Spam verhindern
        return redirect(url_for('login'))
    email = user.email
    token = serializer.dumps(email, salt='email-confirmation')
    confirmation_link = url_for('confirm_email', token=token, _external=True)
    user.confirmation_link = confirmation_link
    db.session.commit()
    msg = Message('NBDF Anmeldung - Email bestätigen',
                  sender=app.config['MAIL_USERNAME'],
                  recipients=[email])
    msg.body = f'Willkommen auf der NBDF Seite.\n\nBitte benutze diesen Link um deinen Account zu bestätigen: {confirmation_link.replace("localhost",server_IP)}\n\nBitte antworte nicht direkt auf diese Email.'
    mail.send(msg)
    flash('Bestätigungs-Email erneut zugesandt', 'info')
    return redirect(url_for('login'))
Example #19
0
def email():
    if request.method == 'POST':
        data = request.get_json(force="true")
        print(data, file=sys.stderr)
        name = data['name']
        subject = "Portfolio Message - " + name
        message = data['message']
        sender = data['email']
        msg = Message(subject,
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = message
        msg.html = "<h1>Message from " + name + "</h1>" + "<p>" + message + "</p>" + "<br/>" + "Respond to: <b>" + sender + "</b>"
        mail.send(msg)

        res = make_response(jsonify({"message": "OK"}), 200)

        return res
Example #20
0
def index():
    form = ContactForm()
    if form.validate_on_submit():
        msg = Message()

        msg.subject = 'You have a new message!'
        msg.sender = form.email.data
        msg.add_recipient(current_app.config['RECIPIENT_EMAIL'])
        msg.body = f"""
        Sender: {form.name.data}
        Sender Email: {form.email.data}
        Subject: {form.subject.data}
        Body: {form.message.data}
        """

        mail.send(msg)
        return redirect(url_for('index'))

    return render_template('index.html', form=form)
Example #21
0
def register():
    context = global_context()
    if current_user:
        if current_user.is_authenticated:
            return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        email = form.email.data
        token = serializer.dumps(email, salt='email-confirmation')
        confirmation_link = url_for('confirm_email',
                                    token=token,
                                    _external=True)
        user_data = {
            'firstname': form.firstname.data,
            'lastname': form.lastname.data,
            'email': form.email.data,
            'password': hashed_password,
            'confirmation_link': confirmation_link,
        }
        user = User(**user_data)
        msg = Message('NBDF Anmeldung - Email bestätigen',
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[email])
        msg.body = f'Willkommen auf der NBDF Seite.\n\nBitte benutze diesen Link um deinen Account zu bestätigen: {confirmation_link.replace("localhost",server_IP)}\n\nBitte antworte nicht direkt auf diese Email.'
        mail.send(msg)
        db.session.add(user)
        db.session.commit()
        flash(
            f'Willkommen {form.firstname.data}, bitte bestätige die Email für deinen Account.',
            'success')
        #context['user_email'] = form.email.data
        return redirect(url_for('login', **context))
    context['form'] = form
    context['title'] = 'Registrieren'
    return render_template('register.html', **context)
Example #22
0
def send_email(form):
    msg = Message(subject=f'{form.subject.data}',
                  sender=os.getenv("Email_User"),
                  recipients=['*****@*****.**'])
    msg.body = f'This message is from: {form.name.data},\n body: {form.body.data}. \n Email: {form.email.data}.'
    mail.send(msg)
Example #23
0
def send_mail(sender, to, body, subject):
    msg = Message(sender=sender, subject=subject, recipients=[to])
    msg.body = body
    msg.html = markdown(msg.body)
    mail.send(msg)
Example #24
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
Example #25
0
def _send_async_email(app, message):
    with app.app_context():
        # TODO: Add events
        mail.send(message=message)
Example #26
0
def send_mail(sender, to, body, subject):
    msg = Message(sender=sender, subject=subject, recipients=[to])
    msg.body = body
    msg.html = markdown(msg.body)
    mail.send(msg)