예제 #1
0
def send_async_email(email_data):
    """Background task to send an email with Flask-Mail."""
    msg = Message(email_data['subject'],
                  sender=current_app.config['MAIL_DEFAULT_SENDER'],
                  recipients=[email_data['to']])
    msg.body = email_data['body']
    mail.send(msg)
예제 #2
0
def new_tree():
  tree = Tree()
  tree_form = NewTree(request.form, tree)
  if request.method == 'POST' and tree_form.validate():
    tree_form.populate_obj(tree)
    tree.city = 'Bochum'
    tree.public = 0
    tree.source = 'Nutzer'
    tree.created_at = datetime.datetime.now()
    tree.modified_at = datetime.datetime.now()
    tree.ip = request.remote_addr
    tree.hostname = socket.gethostbyaddr(request.remote_addr)[0]
    db.session.add(tree)
    db.session.commit()
    msg = Message(recipients=app.config['INFO_MAIL_RECIPIENTS'],
      sender=app.config['INFO_MAIL_SENDER'],
      body=u"ID: %s" % tree.id,
      subject=u"Neuer Baum wurde eingereicht")
    mail.send(msg)
    if request.files['picture'].filename:
      image_data = request.files['picture'].read()
      # write new image data
      open(os.path.join(app.config['IMAGE_UPLOAD_PATH_BASE'], str(tree.id) + '.jpg'), 'w').write(image_data)
      call(['/usr/bin/convert', '-resize', '270x270', os.path.join(app.config['IMAGE_UPLOAD_PATH_BASE'], str(tree.id) + '.jpg'), os.path.join(app.config['IMAGE_UPLOAD_PATH_BASE'], str(tree.id) + '-small.jpg')])
      tree.picture = 1
      db.session.add(tree)
      db.session.commit()
    flash(u'Eintrag wurde gespeichert und wird nun geprüft. Danke fürs Mitwirken!')
    return redirect("/")
  return render_template('new-tree.html', tree_form=tree_form)
예제 #3
0
def send_email(recipients, template, template_ctx, subject=None, funnel_stream_id=None):
    msg = Message()

    # find recipients and check if they are unsubscribed
    for recipient in recipients:
        user = models.User.query.filter_by(email=recipient).first()
        if not user:
            user = models.UserLegacy.query.filter_by(email=recipient).first()
        if not user:
            user = models.UserLegacy(email=recipient)
            db.session.add(user)
        if user.unsubscribed:
            # Just log that this email is not sent due to unsubscribed status and return
            sent_email = models.SentEmail(timestamp=datetime.datetime.utcnow(),
                                          recipients=str(recipients),
                                          subject="USER HAS UNSUBSCRIBED")
            db.session.add(sent_email)
            db.session.commit()
            return
        if not user.unsubscribe_token:
            user.unsubscribe_token = random_pwd(26)
            db.session.add(user)
            db.session.commit()
        template_ctx['unsubscribe_token'] = user.unsubscribe_token

    # generate tracking pixel
    tracking_pixel_id = random_pwd(26)
    template_ctx['tracking_pixel_id'] = tracking_pixel_id

    # set up email
    msg.subject = subject
    msg.recipients = recipients
    msg.html = render_template(template, **template_ctx)
    msg.body = html2text.html2text(msg.html)

    # Actually send email
    mail.send(msg)

    # find if this is for a shop
    shop_id = None
    if template == 'email/review_order.html':
        if 'shop_name' in template_ctx:
            shop_name = template_ctx['shop_name']
            shop = models.Shop.query.filter_by(name=shop_name).first()
            if shop:
                shop_id = shop.id

    # LOG
    sent_email = models.SentEmail(timestamp=datetime.datetime.utcnow(),
                                  recipients=str(recipients),
                                  subject=subject,
                                  template=template,
                                  template_ctx=str(template_ctx),
                                  body=msg.body,
                                  tracking_pixel_id=tracking_pixel_id,
                                  for_shop_id=shop_id,
                                  funnel_stream_id=funnel_stream_id)

    db.session.add(sent_email)
    db.session.commit()
예제 #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('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)
예제 #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 the password, click the following link:
{url_for('users.password_reset', token=token, _external=True)}

If you did not make this request, ignore this email.
'''

    mail.send(msg)
예제 #6
0
def send_email_confirm(email, texto, func):
    token = s.dumps(email, salt='email-confirm')

    msg = Message('Confirmar E-mail',
                  sender='*****@*****.**',
                  recipients=[email])

    link = url_for('.{}'.format(func), token=token, external=True)

    msg.body = '{}: \nhttp://antenacpsbackend-env.xryvsu2wzz.sa-east-1.elasticbeanstalk.com{}'.format(
        texto, link)

    mail.send(msg)
    return jsonify({'Mensagem': 'E-mail enviado com sucesso!'})
예제 #7
0
def forgot_password():
    auth = request.get_json()

    parceiro = Parceiros.query.filter_by(email=auth['email']).first()

    if not parceiro:
        return jsonify({'Mensagem': 'Parceiro não encontrado!'})

    func = 'validar_token'
    link = get_link(parceiro.email, func)

    msg = Message('Redefinição de Senha',
                  sender='*****@*****.**',
                  recipients=[parceiro.email])
    msg.html = render_template('mensagem.html', nome=parceiro.nome, link=link)

    mail.send(msg)
    return jsonify({'Mensagem': 'E-mail enviado com sucesso!'})
예제 #8
0
def send_html_mail(recipients, subject, obj, change, date, url, text):
    templateLoader = jinja2.FileSystemLoader(searchpath=template_dir)
    env = jinja2.Environment(autoescape=True, loader=templateLoader)
    env.filters['printdict'] = format_dict
    body=contextdiff.nesteddiff(obj, change, contextdiff.mail)
    template = env.get_template("notif_mail.html")
    outputText = template.render(
        changes=change,
        subject=subject,
        body=body,
        date=date,
        url=url
    )

    msg = Message(subject,
            sender = "*****@*****.**",
            bcc = list(recipients))
    msg.html = outputText
    msg.body = text
    with app.app_context():
        mail.send(msg)
예제 #9
0
파일: email.py 프로젝트: lesamo12/Microblog
def send_async_email(app,msg):
    with app.app_context():
        mail.send(msg)
예제 #10
0
   if tree_suggest.field == 'picture':
     tree_suggest.value = 0
   else:
     tree_suggest.value = request.args.get('value')
   tree_suggest.created_at = datetime.datetime.now()
   tree_suggest.ip = request.remote_addr
   tree_suggest.hostname = socket.gethostbyaddr(request.remote_addr)[0]
 except ValueError, TypeError:
   abort(500)
 db.session.add(tree_suggest)
 db.session.commit()
 msg = Message(recipients=app.config['INFO_MAIL_RECIPIENTS'],
   sender=app.config['INFO_MAIL_SENDER'],
   body=u"ID: %s\nFeld: %s" % (tree_suggest.tree_id, tree_suggest.field),
   subject=u"Neuer Änderungsvorschlag wurde eingereicht")
 mail.send(msg)
 if tree_suggest.field == 'picture' and request.files['picture'].filename:
   image_data = request.files['picture'].read()
   # write new image data
   open(os.path.join(app.config['SUGGEST_IMAGE_UPLOAD_PATH_BASE'], str(tree_suggest.id) + '.jpg'), 'w').write(image_data)
   call(['/usr/bin/convert', '-resize', '270x270', os.path.join(app.config['SUGGEST_IMAGE_UPLOAD_PATH_BASE'], str(tree_suggest.id) + '.jpg'), os.path.join(app.config['SUGGEST_IMAGE_UPLOAD_PATH_BASE'], str(tree_suggest.id) + '-small.jpg')])
   tree_suggest.value = 1
   db.session.add(tree_suggest)
   db.session.commit()
 ret = {
   'status': 0,
   'duration': round((time.time() - start_time) * 1000),
   'request': {},
   'response': True
 }
 json_output = json.dumps(ret, cls=util.MyEncoder, sort_keys=True)
예제 #11
0
def send_mail(to, subject, content, **kwargs):
    msg = Message(subject=subject, sender='*****@*****.**', recipients=[to])
    msg.body = content
    mail.send(msg)
예제 #12
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
    mail.send(msg)
예제 #13
0
def send_email(recipients,
               template,
               template_ctx,
               subject=None,
               funnel_stream_id=None):
    msg = Message()

    # find recipients and check if they are unsubscribed
    for recipient in recipients:
        user = models.User.query.filter_by(email=recipient).first()
        if not user:
            user = models.UserLegacy.query.filter_by(email=recipient).first()
        if not user:
            user = models.UserLegacy(email=recipient)
            db.session.add(user)
        if user.unsubscribed:
            # Just log that this email is not sent due to unsubscribed status and return
            sent_email = models.SentEmail(timestamp=datetime.datetime.utcnow(),
                                          recipients=str(recipients),
                                          subject="USER HAS UNSUBSCRIBED")
            db.session.add(sent_email)
            db.session.commit()
            return
        if not user.unsubscribe_token:
            user.unsubscribe_token = random_pwd(26)
            db.session.add(user)
            db.session.commit()
        template_ctx['unsubscribe_token'] = user.unsubscribe_token

    # generate tracking pixel
    tracking_pixel_id = random_pwd(26)
    template_ctx['tracking_pixel_id'] = tracking_pixel_id

    # set up email
    msg.subject = subject
    msg.recipients = recipients
    msg.html = render_template(template, **template_ctx)
    msg.body = html2text.html2text(msg.html)

    # Actually send email
    mail.send(msg)

    # find if this is for a shop
    shop_id = None
    if template == 'email/review_order.html':
        if 'shop_name' in template_ctx:
            shop_name = template_ctx['shop_name']
            shop = models.Shop.query.filter_by(name=shop_name).first()
            if shop:
                shop_id = shop.id

    # LOG
    sent_email = models.SentEmail(timestamp=datetime.datetime.utcnow(),
                                  recipients=str(recipients),
                                  subject=subject,
                                  template=template,
                                  template_ctx=str(template_ctx),
                                  body=msg.body,
                                  tracking_pixel_id=tracking_pixel_id,
                                  for_shop_id=shop_id,
                                  funnel_stream_id=funnel_stream_id)

    db.session.add(sent_email)
    db.session.commit()