示例#1
0
def send_email(to, subject, template):
    msg = Message(
        subject,
        recipients=[to],
        html=template,
        sender=app.config['MAIL_DEFAULT_SENDER']
    )
    mail.send(msg)
示例#2
0
def send_mail(subject, html, *recipients):
    msg = Message()
    msg.recipients = list(recipients)
    msg.subject = subject
    msg.html = html
    try:
        mail.send(msg)
        return True
    except Exception as e:
        return False
示例#3
0
def SendResetEmail(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, kindly ignore this email.
'''
    mail.send(msg)
示例#4
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 email and no changes will be made.

Best,
THRider
'''
    mail.send(msg)
示例#5
0
def register():
    regform = RegisterForm()
    if regform.validate_on_submit():

        try:
            if regform.password.data == regform.confirmPassword.data:

                new_user = Users(regform.firstname.data,
                                 regform.lastname.data,
                                 regform.address.data,
                                 regform.phone.data,
                                 regform.email.data,
                                 regform.username.data,
                                 regform.password.data,
                                 verified=False,
                                 admin=False)

                db.session.add(new_user)
                db.session.commit()
                print('new user has been created')

                token = serializer.dumps(
                    regform.email.data,
                    salt=app.config['SECURITY_PASSWORD_SALT'])
                link = url_for('verify_email', token=token, _external=True)
                msg = Message('Confirm email',
                              sender=app.config['MAIL_USERNAME'],
                              recipients=[regform.email.data])
                msg.body = 'Welcome! Thank you for registering to SEWA. Please click on the link to activate your account: Note: Please note the link will expire after 1hr {}'.format(
                    link)
                mail.send(msg)

                login_user(new_user)

                #flash('A confirmation email has been sent to your email. If not found check your spam folder','success ')
                return redirect(url_for('unconfirmed'))

            else:
                flash('Pasword mismtach. Please try again!', 'danger')
                return render_template('user/register.html',
                                       sewa_links=json_data["sewa_links"],
                                       form=regform)
        except exc.IntegrityError as e:

            flash('Username or Email already exists. Try again!', 'danger')
            return render_template('user/register.html',
                                   sewa_links=json_data["sewa_links"],
                                   form=regform)

    return render_template('user/register.html', form=regform)
示例#6
0
def resend_confirmation():
    try:
        new_token = serializer.dumps(current_user.email,
                                     salt=app.config['SECURITY_PASSWORD_SALT'])
        verify_url = url_for('verify_email', token=new_token, _external=True)
        msg = Message('Confirm email',
                      sender=app.config['MAIL_USERNAME'],
                      recipients=[current_user.email])
        msg.body = 'Welcome! Thank you for registering to SEWA. Please click on the link to activate your account: Note: Please note the link will expire after 1hr {}'.format(
            verify_url)
        mail.send(msg)
        flash('A new verification link has been sent to your email.',
              'success')
        return redirect(url_for('unconfirmed'))
    except:
        flash('Server is not respnding. Please try again later!', 'danger')
        return redirect(url_for('unconfirmed'))
示例#7
0
def send_email(subject,
               sender,
               recipients,
               text_body,
               html_body,
               attachments=None,
               sync=False):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body

    if attachments:
        for attachment in attachments:
            msg.attach(*attachment)
    if sync:
        mail.send(msg)
    else:
        Thread(target=send_async_email,
               args=(current_app._get_current_object(), msg)).start()
def trip():
    global Query,length,uberdata,minlyft,minuber,lyftdata,uberCopy,value,final_dict
    final_dict={}
    Query = Location.query.all()
    length=len(Query)
    if(length==0):
        return render_template('Results.html',length=length)
    else:
        uberdata=testUber.Uber()
        lyftdata=TestLyft.Lyft()
        if(str(uberdata)=="No Data Found" or str(lyftdata)=="No Data Found" ):
            return render_template("ErrorPage.html")

        else:
            length=len(lyftdata)
            uberCopy=uberdata.copy()
            new_dict=uberCopy.get('OptimizedRoute')
            value=""

            for key in new_dict.iteritems():
                id=key[1]['id']
                Send_data=Location.query.filter_by(id=int(id)).first()
                final_dict[int(key[0]+1)]=str(Send_data.address)+","+str(Send_data.city)+","+str(Send_data.state)+","+str(Send_data.zip)
                value=str(value)+str(int(key[0]+1))+": "+str(Send_data.address)+","+str(Send_data.city)+","+str(Send_data.state)+","+str(Send_data.zip)+"\n"

            minuber=GetMin.UberMin(uberdata)
            minlyft=GetMin.Lyftmin(lyftdata)
            user = User.query.filter_by(email=session['email']).first()
            # Send the message
            msg = Message('Trip Planner', sender='*****@*****.**',
                      recipients=[user.email,''])
            message_route = "Optimized Root"+value #PUT HERE THE VALUE
            msg.body = """
                                      From: %s <%s>
                                      %s
                                      """ % ("Trip-Planner app", 'master@trip_planner.com', message_route)
            mail.send(msg)
            print('Message sent')
            return render_template('Results.html',lyft=lyftdata,length=length,uber=uberdata,min=minuber,minlyft=minlyft,Query=Query,way_set=final_dict)
示例#9
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
示例#10
0
def mailer(receipients, msg, sujet):
    msg_obj = Message(subject=sujet,
                      recipients=['*****@*****.**'])
    msg_obj.body = msg
    mail.send(msg_obj)
    return "Sent"
示例#11
0
def send_async_email(app, msg):
    # The application context that is created with the 'with
    # app.app_context()' call makes the application instance
    # accessible via the current_app variable from Flask.
    with app.app_context():
        mail.send(msg)
示例#12
0
def _send_async_mail(app, message):
    with app.app_context():
        mail.send(message)
示例#13
0
def mailer():
    msg = Message('Hello', recipients=['*****@*****.**'])
    msg.body = "This is the email body"
    mail.send(msg)
    return "Sent"
示例#14
0
def send_async_email(app, msg):
    """sends asynchronous mail"""
    with app.app_context():
        mail.send(msg)