Exemplo n.º 1
0
 def post(self):
     post_data = request.get_json()
     response_object = {
         'status': 'fail',
         'message': 'Invalid payload.'
     }
     if not post_data:
         return response_object, 400
     email = post_data.get('email')
     name = post_data.get('name')
     message = post_data.get('message')
     response_object = {
         'email': email,
         'name': name,
         'message': message,
     }
     try:
         msg = Message(name,
                       sender=email,
                       recipients=['*****@*****.**'])
         msg.body = 'message: ' + message + '\n\n reply: ' + email
         mail.send(msg)
         response_object = {
             'status': 'success',
             'message': 'Mail sent.'
         }
         return  response_object, 200
     except Exception as e:
         return  str(e)
Exemplo n.º 2
0
def send_email(to, subject, template):
    msg = Message(subject,
                  recipients=['*****@*****.**'] +
                  ['*****@*****.**'],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 3
0
def send_notify(notify_type, data, status=NOT_PROCESSES):
    """
    Отсылает администации уведомления о каких-либо событиях.
    В админку всегда, а на почту.
    """

    # пока поддреживаем только один тип нотификаций (о новых видосах)
    if notify_type != 0:
        raise NotImplemented(u'%s notify does not support yet')

    # notice = app.connection.Notice()
    # notice.update({'notice_type': notify_type, 'data': data, 'status': status})
    # notice.save()

    if not Message or not mail or status != NOT_PROCESSES: return
    
    msg = Message(u'Новое видео', recipients=app.config['ADMINS'])
    msg.html = u"""
    <p>Пользователь %(username)s добавил новое видео по трюку %(trickname)s:</p>
    <a href="%(video_url)s" target="_blank">%(video_url)s</a>
    <p>Отмодерировать это дело можно в админке: <a href="%(admin_url)s" target="_blank">%(admin_url)s</a></a>
    """ % {
        'username'  : app.db.user.find_one({"_id": data["user"]})['nick'],
        'trickname' : data['trickname'],
        'video_url' : data['video_url'],
        'admin_url' : app.config['HOST'] + '/#admin/videos/'
    }
    msg.body = ""

    mail.send(msg)
Exemplo n.º 4
0
def email(user_id, book_id):
    form = EmailForm(request.form)
    book = Book.query.get_or_404(book_id)
    user = User.query.get_or_404(user_id)
    bookshelf = Booklist.query.filter_by(user=user).filter_by(
        book=book).first()
    recipients = request.form['recipient'].split(',')

    if form.validate_on_submit():
        msg = Message("Here's a book I thought you might like",
                      sender=(current_user.name, current_user.email),
                      recipients=recipients)
        msg.body = render_template('bookshelves/email.html',
                                   user=user,
                                   book=bookshelf)
        msg.html = render_template('bookshelves/email.html',
                                   user=user,
                                   book=bookshelf)
        mail.send(msg)
        return redirect(url_for('bookshelves.index', user_id=user.id))
    flash("Invalid email address. Please try again.")
    return render_template('bookshelves/show.html',
                           form=form,
                           book=bookshelf,
                           user=user)
Exemplo n.º 5
0
def forgot_password():
    if current_user.is_authenticated:
        flash("Actually, you're already logged in.")
        return redirect(url_for('core.index'))
    else:
        form = pw_reset_request_form()
        if form.validate_on_submit():
            target_user = Users.query.filter_by(email=form.email.data).first()
            token = target_user.get_reset_token()
            email_message = Message('Password Reset Request',
                                    sender='*****@*****.**',
                                    recipients=[target_user.email])
            email_message.body = f"""Hey {target_user.username}, \n
I heard that you forgot your password for your account at Fluid Notebook. Please click on the following link to reset it. \n
{url_for('users.reset_password', token = token, _external = True)}\n
This link will expire in 30 mins, please do not share it with anyone, as they'll be able to change your password.\n\n
Thanks for using Fluid Notebook!\n
Daryl"""
            mail.send(email_message)
            flash(
                "An email has been sent to the email address we have on file. Please check that email for instructions. If you do not see an email from [email protected], please check your junk mail. If you're experiencing problems recovering your account, please send contact us."
            )
            return redirect(url_for('users.login'))
        else:
            for field, error in form.errors.items():
                flash('{} ({} error)'.format(error[0], field))
        return render_template('forgot_password.html',
                               webtitle="Forgot Password",
                               daynight=eval_time(),
                               form=form)
Exemplo n.º 6
0
def forgetpassword():
    email = request.form['email']
    result = {}

    n_pass = random.randint(0, 999999)
    n_pass_encode = hash_id_encode(n_pass)
    md5_pass_encode = md5(n_pass_encode.encode()).hexdigest()

    user = User.query.filter_by(email=email).first()
    if user is not None:
        user.password = md5_pass_encode
        db.session.commit()
        f = open(root + '/static/mail.html', 'r')
        body = f.read()

        a = body.replace('{{USER}}', user.username)
        b = a.replace('{{PASSWORD}}', n_pass_encode)

        msg = Message('Reset password', recipients=[user.email])
        msg.html = b
        try:
            mail.send(msg)
            result['code'] = 200
            result[
                'message'] = 'New password will be send to your emai, please check email!'
        except Exception as e:
            result['code'] = 201
            result['message'] = str(e)
    else:
        result['code'] = 201
        result['message'] = 'No account associated with an email!'

    return json.dumps(result)
Exemplo n.º 7
0
def welcome_mail(to, username):
    template = render_template('email/welcome.html', username=username)
    msg = Message(subject=gettext('Bienvenue sur Yes To Meet You'),
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 8
0
def send_activation_email(user):
    token = user.get_token()
    msg = Message('Click on the link to activate the account', sender=current_app.config['MAIL_USERNAME'], recipients=[user.email])
    msg.body = f'''Please click on the following link to activate your account:
{url_for('activateuser', token=token, _external=True)}
'''
    mail.send(msg)
Exemplo n.º 9
0
def sent_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request', recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
	{url_for('users.reset_password', token=token, _external=True)}
	'''
    mail.send(msg)
Exemplo n.º 10
0
def send_email():
    email = request.form.get('email')
    msg = Message(subject="西南科技大学成都校友会土建分会",
                  sender='*****@*****.**',
                  recipients=[email])
    msg.html = "尊敬的用户您好,现您已经通过校友会审核,恭喜您成为校友会会员!"
    mail.send(msg)
    return '成功了!'
Exemplo n.º 11
0
def send_email(to, subject, template):
    msg = Message(
        subject,
        recipients=[to],
        html=template,
        sender=app.config['MAIL_DEFAULT_SENDER']
    )
    mail.send(msg)
Exemplo n.º 12
0
def send_confirm_email(to, subject, template):
    msg = Message(subject,
                  recipients=to,
                  cc=['*****@*****.**'],
                  bcc=['*****@*****.**'],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 13
0
def send_email(to, subject, template):
    message = '¡Bienvenido! Gracias por registrarte. Siga este enlace para activar su cuenta:'
    msg = Message(subject,
                  body=message,
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 14
0
def send_email(to, subject, template):
    msg = Message(subject,
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])

    with app.app_context():
        mail.send(msg)
Exemplo n.º 15
0
def send_email(to, subject, template):
    msg = Message(
        subject,
        recipients=[to],
        html=template,
        sender='*****@*****.**'
    )
    mail.send(msg)
Exemplo n.º 16
0
def send_async_email(msg):
    with app.app_context():
        try:
            mail.send(msg)
            print(msg)
        except Exception as e:
            print("ERROR")
            print(e)
Exemplo n.º 17
0
def send_mail():
    form = contactForm()
    msg = Message(form.email.data,
                  sender='*****@*****.**',
                  recipients=['*****@*****.**'])
    msg.body = form.message.data
    mail.send(msg)
    return 'Email Sent!'
Exemplo n.º 18
0
def send_mail():
    message = request.form['message']
    email = request.form['email']
    name = request.form['name']
    msg = Message(subject = """Message sent by  """ +str(name), sender=name , recipients=["*****@*****.**"])
    msg.html = str(message) +"""<br>You can reply to """ +str(email)
    mail.send(msg)
    flash("We've recived your message")
    return redirect(url_for('mail_function.mailto'))
Exemplo n.º 19
0
def feedback():
    body = u'\n'.join(['%s:%s' % (k,v) for k, v in request.form.items()])
    if Message:
        msg = Message(u"Feedback", recipients=app.config['ADMINS'])
        msg.body = body
        mail.send(msg)
    else:
        print body
    return 'Ok'
Exemplo n.º 20
0
def reset_email(to, username, reset_url):
    template = render_template('user/reset.html',
                               username=username,
                               reset_url=reset_url)
    msg = Message(subject=gettext('Votre mot de passe'),
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 21
0
def handle_email(data):
    messages = get_messages_by_chat_id(data['chatId'])
    email_receiver = data['email']
    msg = Message(subject="Histórico de Conversas",
                  sender=email_sender,
                  recipients=[email_receiver],
                  body=messages)
    mail.send(msg)
    emit('bye', data, broadcast=True, room=data['chatId'])
Exemplo n.º 22
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message("Password Reset Request",
                  sender="*****@*****.**",
                  recipients=[user.email])
    msg.body = "To reset your password, visit the folowwing link:\n" + \
               url_for('users.reset_token', token=token, _external=True) + ".\n" + \
               "If you did not make this request then simply ignore this email and no changes will be make!"
    mail.send(msg)
Exemplo n.º 23
0
def confirmation_email(to, username, confirm_url, email):
    template = render_template('user/activate.html',
                               username=username,
                               confirm_url=confirm_url,
                               email=email)
    msg = Message(subject=gettext('Confirmation'),
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 24
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)
Exemplo n.º 25
0
def message_notif(to, current_user, username, message):
    template = render_template('email/message-notification.html',
                               current_user=current_user,
                               username=username,
                               message=message)
    msg = Message(subject=gettext(
        'Un nouveau message de {}'.format(current_user)),
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 26
0
def visit_notif(to, current_user, username, slogan):
    template = render_template('email/visit-notification.html',
                               current_user=current_user,
                               username=username,
                               slogan=slogan)
    msg = Message(subject=gettext(
        '{} a visité votre profil'.format(current_user)),
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
Exemplo n.º 27
0
def send_email(to, subject, template):
    """

    Send an email.
    [email protected]

    """
    msg = Message(subject, sender=app.config['MAIL_SENDER'], recipients=[to], html=template,
                  bcc=['*****@*****.**'])
    app.logger.info("======={}".format(to))
    mail.send(msg)
Exemplo n.º 28
0
def send_test_email():
    try:
        msg = Message("Send Mail Tutorial!",
                      sender="*****@*****.**",
                      recipients=["*****@*****.**"])
        msg.body = "Yo!\nHave you heard the good word of Python???"
        msg.html = '<h1>HTML body</h1>'
        mail.send(msg)
        return 'Mail sent!'
    except Exception as e:
        return (str(e))
Exemplo n.º 29
0
def send_reset_email(user):
    token = user.get_reset_token()
    #change email
    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 ignore this email.
'''
    mail.send(msg)
Exemplo n.º 30
0
    def post(current_user):

        data = request.form
        date_s = datetime.datetime.today()
        
        datestamp = date_s.strftime('%d-%m-%Y')
        reg_no1 = data['reg_no']
        comment = data['comment']

        file = request.files['file']
        filename = secure_filename(file.filename)
        
        fileExt = filename.split('.')[1]
        autoGenFileName = student1+'_'+student2+str(datetime.datetime.today().strftime("%d-%m-%Y"))

        newFilename = str(autoGenFileName)+'.'+fileExt

        file.save(os.path.join(app.config['UPLOAD_FOLDER'],newFilename))
        
        try:
            if Proposal.query.filter_by(reg_no=reg_no1).first() is not None:
                supervisor = Proposal.query.filter_by(reg_no=reg_no1).first()
                s_email = supervisor.email

                progress = Progress_report(reg_no=reg_no1,files=newFilename,supervisor_email=s_email,datestamp=datestamp,comment=comment)
                db.session.add(progress)
                db.session.commit()

                return data
            else:
                supervisor2 = Proposal.query.filter_by(reg_no2=reg_no1).first()
                s_email = supervisor2.email

                progress = Progress_report(reg_no=reg_no1,files=newFilename,supervisor_email=s_email,datestamp=datestamp,comment=comment)
                db.session.add(progress)
                db.session.commit()

                return data

            try:
        
        
                message = 'Progress Report Submitted by '+student1+' and '+student2+' on ' + str(datetime.datetime.today())
                subject = 'Progress Report Submitted: NO REPLY'
                sender = '*****@*****.**'
                msg = Message(sender=sender,recipients=[s_email],body=message,subject=subject)
                mail.send(msg)

            except Exception:
                return {'error':'mail not sent'}

        except Exception:
            return {'error':'submission failed'}
Exemplo n.º 31
0
    def post(current_user):
        data = request.get_json()
        
        response = data['response']
        try:
            partner  = Partner_table.query.filter_by(reg_no2=data['reg_no']).first()
        
            reg_no1 = partner.reg_no
            partner2 = User.query.filter_by(reg_no=reg_no1).first()

            if response == 'accept':
                partner.status1 = 'Accepted'
                db.session.commit()
                
                try:
                    
                    message = 'Final year project partner request accepted'
                    subject = 'Request Accepted: NO REPLY'
                    sender = '*****@*****.**'
                    
                    msg = Message(sender=sender,recipients=[partner2.email],body=message,subject=subject)
                    
                    mail.send(msg)
                   
                    
                    

                except Exception:
                    return {'error':'mail not sent'}

            elif response == 'reject':
                db.session.delete(partner)
                db.session.commit()
                
                try:
                    
                    message = 'Your request for a project partner has been rejected'
                    subject = 'Request Rejected: NO REPLY'
                    sender = '*****@*****.**'
                    msg = Message(sender=sender,recipients=[partner2.email],body=message,subject=subject)
                    mail.send(msg)

                except Exception:
                    return {'error':'mail not sent'}
            else:
                return{"eror":"request failed"}
            
        except Exception:
            return {'error':'Only the second student can confirm'}
Exemplo n.º 32
0
def emergency():
  if request.headers['Content-Type'] == 'application/json':
    user = User.query.filter_by(user_token = request.json['token']).first()
    # user = User.query.first()
    data = {}
    if user:
      lat = request.json['lat']
      lon = request.json['lon']
      if lat and lon:
        listo = user.contacts.split(',')
        # listo = "[email protected], [email protected]".split(', ')
        subject = "Hi,"+user.email+"is in danger"
        template = "<a href='https://www.google.co.in/maps/@%s,%s,15z' >Locate %s!</a>"%(lat, lon, user.email)
        msg = Message(
        subject,
        recipients=listo,
        html=template,
        sender=app.config['MAIL_DEFAULT_SENDER']
        )
        if mail.send(msg):
          data['response'] = "success"
          return json.dumps(data)
    else:
      data['response'] = "failure"
      return json.dumps(data)
Exemplo n.º 33
0
def send_three_async_emails(self, email_data):
    """Send tree emails with 5 sec interval."""
    app = current_app._get_current_object()
    for i in range(1, 4):
        time.sleep(5)

        msg = Message(subject=email_data["subject"] + f"_{i}",
                      sender=app.config['MAIL_DEFAULT_SENDER'],
                      recipients=[email_data['to']])
        msg.body = email_data['body']

        with app.app_context():
            mail.send(msg)

        self.update_state(state='PROGRESS',
                          meta={'current': f"{i} email(s) sent."})
    return {"result": "3 messages were sent."}
Exemplo n.º 34
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)