示例#1
0
def send_email(to, subject, template):
    msg = Message(
        subject,
        recipients=[to],
        html=template
    )
    mail.send(msg)
示例#2
0
def contact():
    form = CustomerMessageForm()
    if form.validate_on_submit():
        msg = Message('Customer inquisition from your website',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = f'''
From: \n\t{form.customer_name.data}
\nPhone: \n\t{form.customer_phone.data}
\nEmail: \n\t{form.customer_email.data}
\nMessage: \n\t{form.customer_message.data}
'''
        # sending the message
        mail.send(msg)

        # add all of this to the database:
        # time will be stored in UTC format and added automatically
        customer = Customer_Message(name=form.customer_name.data,
                                    email=form.customer_email.data,
                                    phone=form.customer_phone.data,
                                    message=form.customer_message.data)
        db.session.add(customer)
        db.session.commit()
        flash('Message sent thank you. We will be in touch', 'success')
        return redirect(url_for('main_bp.home'))
    else:
        flash('All fields are required.', 'danger')
    return render_template('contact.html', form=form)
示例#3
0
文件: utils.py 项目: PDivH/flask_app
def send_reset_email(user):
    print(f"Email sent to {user.username} at {user.email}")
    token = user.get_reset_token()
    print(f"token: {token}")
    msg = Message("Request to Reset Password", recipients=[user.email])
    msg.sender = ("flask_app Team", "no-reply@flask_app.io")
    msg.html = f"""<body style="font-family: sans-serif; font-size: 16px; line-height: 24px;">
<h1 style="font-size: 24px; line-height: 32px;">Hello {user.username}!</h1>
<p>
    It looks like you've requested to reset your flask_app's password. If that really is the case, you only need to follow the link <a href="{url_for("users.reset_token", token=token, _external=True)}">Reset Password</a>.
</p>
<p>
Otherwise, you can just ignore this email and nothing will be changed.
</p>
<p>
Thanks for being a valuable member! Happy Bloging!
</p>
<p>
The flask_app Team
<span style="font-size: 24px; color: red;">&hearts;</span>
<span style="font-size: 24px; color: green;">&hearts;</span>
<span style="font-size: 24px; color: blue;">&hearts;</span>
</p>
</body>
    """
    mail.send(msg)
示例#4
0
def send_async_email(flask_app, msg):
    with flask_app.app_context():
        try:
            mail.send(msg)
        except SMTPException, e:
            #return str("Please enter a valid email id")
            return str(e)
示例#5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    form = RegistrationForm()
    if form.validate_on_submit():

        msg = Message('Thanks for Registering!',
                      sender='*****@*****.**',
                      recipients=[str(form.email.data)])
        msg.body = "Hi there! Thanks for registering to Cat Wiki!\n\nYour username is: " + str(
            form.username.data
        ) + "\n\nThank you for using our website, we hope you have an excellent day!"
        mail.send(msg)

        hashed = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed)
        user.save()

        return redirect(url_for('login'))

    return render_template('register.html', title='Register', form=form)
示例#6
0
def send_reset_email(coordo):
    token = coordo.get_reset_token()
    msg = Message('Réinitialisation de mot de passe',
                  sender=LOP_LOGIN,
                  recipients=['*****@*****.**'])
    msg.body = f''' Pour réinitialiser votre mot de passe : {url_for('coordinateurs.reset_token', token=token, _external=True)}'''
    mail.send(msg)
示例#7
0
def send_suggestion():
    text = "Either this is a test or something went wrong with the parsing of the suggestion, see server log for further information"
    log(INFO, "A suggestion was submitted")
    if 'HTTP_ORIGIN' not in request.environ or request.environ['HTTP_ORIGIN'] != 'https://mooncaker.theboringbakery.com':
        log(WARNING, "A suggestion from a non-approved domain was made")
        return "<h1>We are sorry but we cannot validate the origin of this request, please visit theboringbakery.com for the correct interaction.</h1>"

    text = str(request.form)
    msg = Message(subject="Mooncaker: suggestion made",
                  body=text,
                  sender=app.config['MAIL_USERNAME'],
                  recipients=app.config['MAIL_RECIPIENTS'])
    mail.send(msg)
    # send automatic response
    msg = Message(subject="Mooncaker: thanks for your suggestion!",
                  body=f"Dear {request.form['username']},\n"
                  + f"we've received your suggestion about {request.form['reason']}.\n"
                  + "We really value your feedback and we'll do our best to "
                  + "follow all of your suggestions in the shortest amount of time possible."
                  + "Kind regards,\n The Mooncaker developers team",
                  sender=app.config['MAIL_USERNAME'],
                  recipients=request.form['email'])
    mail.send(msg)
    log(INFO, "The suggestion was successfully sent")
    return redirect("https://mooncaker.theboringbakery.com/#/response_suggestion", code=301)
示例#8
0
def send_email_invitation(coordo):
    token = coordo.get_reset_token()
    msg = Message("Message d'invitation",
                  sender=LOP_LOGIN,
                  recipients=['*****@*****.**'])
    msg.body = f''' Pour devenir coordinateur de l'Ouvre Porte :

    {url_for('coordinateurs.register', token=token, _external=True)}'''
    mail.send(msg)
示例#9
0
def account():
    username_form = UpdateUsernameForm()
    password_form = UpdatePasswordForm()
    profile_pic_form = UpdateProfilePicForm()

    if password_form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            password_form.new_password.data).decode("utf-8")

        msg = Message('Password Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your password has been updated! Please reply to this e-mail if you did not request this change."
        mail.send(msg)

        current_user.modify(password=hashed)
        current_user.save()

        return redirect(url_for('users.account'))

    if username_form.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        current_user.username = username_form.username.data

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('users.account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('users.account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           password_form=password_form,
                           profile_pic_form=profile_pic_form,
                           image=image)
def send_verification_mail(user):
	token = user.get_reset_token()
	msg = Message('PASSPORT SYSTEM', sender = '*****@*****.**', recipients= ['*****@*****.**'])

	msg.body =f'''verify link here:{url_for('verify', token = token, _external = True)}

				applicnt details:{url_for('applicant', token = token, _external=True)}

	''' 
	mail.send(msg)
示例#11
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    print(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)
示例#12
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='noreply@artist_portfolio.com',
                  recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
{url_for('users_bp.reset_token', token=token, _external=True)}
If you did not make this request then simply ignore this email and no changes will be made.
Also, hit John up, because that means someone might be messing with your account
'''
    mail.send(msg)
    def _send_email_of_cancellation(arrangement_id):
        users = arrangement_dao.get_users_from_reservation(
            arrangement_id=arrangement_id
        )
        if len(users) > 0:
            msg = Message('Cancellation',
                          sender='*****@*****.**',
                          recipients=[u.User.email for u in users])

            msg.body = f'You arrangement {users[0].destination} ' \
                       f'has been cancelled.'
            mail.send(msg)
示例#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('main.reset_token', token=token, _external=True)}
Please note: This token will expire in 30 minutes from the time this email is sent. 

If you did not make this request, please ignore this email. No chnages will be made.
'''
    mail.send(msg)
示例#15
0
def send_verification_email(user):
    """send email to verify email is realllll"""
    token = user.get_verification_token()
    msg = Message('Account activation - Bib Stonks',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f""" To activate your account, please visit the following link:

{url_for('accounts.email_verification', token=token, _external=True)}

If you did not register an account with Bib Stonks, please ignore this email! :)
    """
    mail.send(msg)
示例#16
0
def send_reset_email(user):
    """external returns absolute vs relative url"""
    token = user.get_reset_token(expires_sec=84600)
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, please visit the following link:

{url_for('accounts.reset_password', token=token, _external=True)}
    
If you did not make this request please ignore this email! :)
    '''
    mail.send(msg)
示例#17
0
def send_applied_email():
    mail_to_user_list = User.query.filter(User.rank < 6).all()
    mail_to_email_list = []
    for user in mail_to_user_list:
        mail_to_email_list.append(user.email)
    msg = Message('We have a new applicant',
                  sender='*****@*****.**',
                  recipients=None,
                  bcc=mail_to_email_list)
    msg.body = f'''Someone just applied to join. Please login to the admin panel of the website to approve, reject or just message the appliciant. 
{url_for('manage.admin', _external=True)}

'''
    # print("Here are the people who should get the mail", mail_to_email_list)
    # print("Here is the url for manage.admin: ", url_for('manage.admin', _external=True))
    mail.send(msg)
示例#18
0
def account():
    username_form = UpdateUsernameForm()
    profile_pic_form = UpdateProfilePicForm()

    if username_form.validate_on_submit():
        # current_user.username = username_form.username.data

        temp = User.objects(username=current_user.username).first()

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           profile_pic_form=profile_pic_form,
                           image=image)
示例#19
0
def send_mail():
    recipient = request.args.get('email')
    pdf = request.args.get('pdf') == 'true'
    csv = request.args.get('csv') == 'true'

    exporter = DBExporter(mongo.db, 'log')
    msg = Message(
        subject=gettext(u'Export štatistík z aplikácie Octavia Proxy'),
        recipients=[recipient])
    msg.html = render_template('email-template.html')
    if pdf:
        exporter.all_to_pdf()
        with open(config['STATIC_PATH'] + 'stats.pdf', 'rb') as fp:
            msg.attach("statistics.pdf", "application/pdf", fp.read())
    if csv:
        exporter.all_to_csv()
        with open(config['STATIC_PATH'] + 'export.csv', 'rb') as fp:
            msg.attach("statistics.csv", "text/csv", fp.read())
    mail.send(msg)

    return 'success'
示例#20
0
def email_accueillant(acc_id):
    acc = Accueillant.query.get_or_404(acc_id)
    dict_emails = get_conversations(Email_OP.query.distinct())
    form = SendMailForm()
    if form.validate_on_submit():
        emails_re = "([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"
        recipients = re.findall(emails_re, "*****@*****.**")
        recipients = list(map(str.lower, recipients))
        cc = re.findall(emails_re, form.destinataire_copie.data)
        cc = list(map(str.lower, cc))
        msg = Message(subject=form.object_.data,
                      body=form.body.data,
                      recipients=recipients,
                      cc=cc)
        mail.send(msg)
        return redirect(
            url_for('accueillants.liste_accueillants') + f"#{acc.id}")
    elif request.method == 'GET':
        form.destinataire.data = acc.email
    return render_template('email_accueillant.html',
                           accueillant=acc,
                           emails=dict_emails,
                           title="Accueillants",
                           form=form)
示例#21
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
def send_mail(user):
		msg = Message('PASSPORT SYSTEM', sender = '*****@*****.**', recipients= [user.email])

		msg.body = f'''passport will be dispatched soon ''' 
		mail.send(msg)
示例#23
0
def cat_detail(cat_name):
    client = CatClient()
    attributes_to_keep = [
        'affection_level', 'child_friendly', 'dog_friendly', 'energy_level',
        'grooming', 'hypoalergenic'
    ]

    image_result, breed_result = client.retrieve_cat_by_id(cat_name)
    ratings = dict()
    for key in breed_result[0].keys():
        value = str(breed_result[0][key])
        if value.isdigit() and key in attributes_to_keep:
            new_key = key.replace('_', ' ').capitalize()
            ratings[new_key] = (range(int(value)), range(5 - int(value)))

    #if type(image_result) == dict:
    #    return render_template('movie_detail.html', error_msg=result['Error'])

    if len(image_result) == 0 or len(breed_result) == 0:
        return render_template('cat_detail.html', error_msg="error")

    picform = ProposePicForm()
    if picform.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        msg = Message('Upload Request',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Thanks for requesting to upload an image to breed:" + str(
            cat_name) + "!\nYour image is attached to this email"
        msg.attach(picform.new_pic.data.filename, 'images/png',
                   picform.new_pic.data.read())
        mail.send(msg)

        msg = Message('Upload Request',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = "Someone is requesting to upload image to breed: " + str(
            cat_name)
        msg.attach(picform.new_pic.data.filename, 'images/png',
                   picform.new_pic.data.read())
        mail.send(msg)

        img = picform.new_pic.data
        filename = secure_filename(img.filename)

        pim = CatImage(
            commenter=load_user(current_user.username),
            date=current_time(),
            im=None,
            cat_name=cat_name,
        )
        pim.save()
        pim.im.put(img.stream, content_type='images/png')
        pim.save()

        return redirect(url_for('features.cat_detail', cat_name=cat_name))

    form = CatReviewForm()
    if form.validate_on_submit():
        review = Review(
            commenter=load_user(current_user.username),
            content=form.text.data,
            date=current_time(),
            cat_name=cat_name,
        )

        review.save()
        return redirect(request.path)

    reviews_m = Review.objects(cat_name=cat_name)
    reviews = []
    for r in reviews_m:
        reviews.append({
            'date': r.date,
            'username': r.commenter.username,
            'content': r.content,
            'image': images(r.commenter.username)
        })

    return render_template('cat_detail.html',
                           form=form,
                           image=image_result[0],
                           cat=breed_result[0],
                           ratings=ratings,
                           reviews=reviews,
                           picform=picform)
示例#24
0
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
#    Thread(target=send_async_email, args=(app, msg)).start()
    mail.send(msg)
示例#25
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)