当前位置: 首页>>代码示例>>Python>>正文


Python Mail.send方法代码示例

本文整理汇总了Python中flask_mail.Mail.send方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.send方法的具体用法?Python Mail.send怎么用?Python Mail.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_mail.Mail的用法示例。


在下文中一共展示了Mail.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_mail

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def send_mail(recipient,hash_code):
	mail = Mail(app)

	msg = Message("Your python snippet",sender="[email protected]",recipients=[recipient])
	msg.html = render_template("email.html",emailid=recipient.split('@')[0],link="http://pypad.herokuapp.com/get/"+hash_code)

	mail.send(msg)
开发者ID:sri-jay,项目名称:pypad,代码行数:9,代码来源:main.py

示例2: callmeCreate

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def callmeCreate():
    jsonData = request.get_json(force=True)
    if not (jsonData and 'name' in jsonData and 'phone' in jsonData): #check not-nullable fields
        abort(400)

    #set gmail settings
    app.config.update(
    MAIL_SERVER='smtp.gmail.com',
    MAIL_PORT=465,
    MAIL_USE_SSL=True,
    MAIL_USERNAME='[email protected]',
    MAIL_PASSWORD=MAIL_PASS,
    MAIL_DEFAULT_SENDER=('ВИССОН', '[email protected]')
    )
    mail = Mail(app)


    #and send email to me
    try: #send to buyer
        msg = Message("ВИССОН", recipients=["[email protected]"])
        msg.html = "Заявка перезвонить <br> имя: %s <br> номер: %s <br>" % (jsonData.get("name"), jsonData.get("phone"))
        mail.send(msg)
    except BaseException as e:
        print(str(e))
        abort(400)

    return str(True)
开发者ID:700ghz,项目名称:VissonShop,代码行数:29,代码来源:runVissonNv.py

示例3: sendMail

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
    def sendMail(self, app, form):
        app.config['MAIL_SERVER']='smtp.gmail.com'
        app.config['MAIL_PORT'] = 465
        app.config['MAIL_USERNAME'] = Constants.ADMIN_MAIL_ADDR
        app.config['MAIL_PASSWORD'] = Constants.ADMIN_MAIL_PASS
        app.config['MAIL_USE_TLS'] = False
        app.config['MAIL_USE_SSL'] = True
        mail = Mail(app)

        #generate encrypt key
        encryptkey = Script.encode(form['mail'])

        # read file and prepare mail body
        txtBody = ''
        with open(Constants.MAIL_TEMPLATE_FILE) as f:
            content = f.readlines()
            #content = [x.strip() for x in content]
            for row in content:
                row = row.replace("%ACTIVATION_LINK%", "http://localhost/activate?mail={0}&encryptkey={1}".format(form['mail'], encryptkey))
                row = row.replace("%MAIL_ADDRESS%", form['mail'])
                row = row.replace("%FIRSTNAME%", form['firstname'])
                row = row.replace("%REGISTRATION_DATE%", strftime("%Y-%m-%d %H:%M:%S", gmtime()))
                txtBody +=row

        msg = Message('Registration', sender = Constants.ADMIN_MAIL_ADDR, recipients = [form['mail']])
        msg.body = txtBody
        mail.send(msg)
开发者ID:boldoo1900,项目名称:pythonweb,代码行数:29,代码来源:register.py

示例4: send_email

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
 def send_email(self, register_user):
     """
         Method for sending the registration Email to the user
     """
     try:
         from flask_mail import Mail, Message
     except:
         log.error("Install Flask-Mail to use User registration")
         return False
     mail = Mail(self.appbuilder.get_app)
     msg = Message()
     msg.subject = self.email_subject
     url = url_for('.activation', _external=True, activation_hash=register_user.registration_hash)
     msg.html = render_template(self.email_template,
                                url=url,
                                username=register_user.username,
                                first_name=register_user.first_name,
                                last_name=register_user.last_name)
     msg.recipients = [register_user.email]
     try:
         mail.send(msg)
     except Exception as e:
         log.error("Send email exception: {0}".format(str(e)))
         return False
     return True
开发者ID:berlotto,项目名称:Flask-AppBuilder,代码行数:27,代码来源:registerviews.py

示例5: email_errors

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def email_errors():
  beginningform = TimeForm(request.form)
  endform = TimeForm(request.form)

  if request.method == 'POST':
		beginning = beginningform.year + beginningform.month + beginningform.day + beginningform.hour + beginningform.min + beginningform.sec
		end = endform.year + endform.month + endform.day + endform.hour + endform.min + endform.sec
		
		
		begformatted = "%s/%s/%s %s:%s:%s" %(beginningform.month, beginningform.day, beginningform.year, beginningform.hour, beginningform.min, beginningform.sec)
		endformatted = "%s/%s/%s %s:%s:%s" %(endform.month, endform.day, endform.year, endform.hour, endform.min, endform.sec)
		report = "Between %s and %s, the following errors occurred:\n" %(begformatted, endformatted)
		
		errorcount = error_handling.count_errors(int(beginning), int(end))
		for error in errorcount:
			report += "%d of error \"%s\"\n" %(errorcount[error], error_handling.db.lindex(error, 0))	

		# move this to mail module
		ADMINS = ["[email protected]"]
		msg = Message("Error Aggregation Report", sender = "[email protected]", recipients = ADMINS)
		msg.body = report
		mail = Mail(app)
		mail.send(msg)

		return render_template('email_errors.html', form = beginningform) 

  elif request.method == 'GET':
    return render_template('email_errors.html')		
开发者ID:TwentyDW,项目名称:Error-Aggregation-Flask-App,代码行数:30,代码来源:routes.py

示例6: rims_add

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def rims_add():
    form = RimForm(request.form)

    if request.method == "POST" and form.validate_on_submit():

        rim = Rims()
        form.populate_obj(rim)
        db.session.add(rim)
        db.session.commit()

        flash("Rim Created")

        if app.config.get('MAIL_SERVER', None):
            mail = Mail(app)
            body = render_template('rims_email.txt.j2', form=form, rim=rim)

            msg = Message(subject="New Rim submitted",
                          body=body,
                          recipients=[app.config.get('MAIL_TO', None)])
            try:
                mail.send(msg)
            except Exception as e:
                app.logger.error(e)

        return redirect(url_for("wheel_add_rim", rim_id=rim.id))

    else:
        for e in form.errors.items():
            flash(f"{e[0]} - {e[1][0]}")

    return render_template('rims_add.html.j2',
                           form=form)
开发者ID:foozmeat,项目名称:Wheelbuilder,代码行数:34,代码来源:app.py

示例7: hubs_add

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def hubs_add():
    form = HubForm(request.form)

    if request.method == "POST" and form.validate_on_submit():

        hub = Hubs()
        form.populate_obj(hub)
        db.session.add(hub)
        db.session.commit()

        flash("Hub Created")

        if app.config.get('MAIL_SERVER', None):
            mail = Mail(app)

            body = render_template('hubs_email.txt.j2', form=form, hub=hub)

            msg = Message(subject="New Hub submitted",
                          body=body,
                          sender="[email protected]",
                          recipients=[app.config.get('MAIL_TO', None)])
            try:
                mail.send(msg)
            except Exception as e:
                app.logger.error(e)

        return redirect(url_for("wheel_add_hub", hub_id=hub.id))

    else:
        for e in form.errors.items():
            flash(f"{e[0]} - {e[1][0]}")

    return render_template('hubs_add.html.j2',
                           form=form)
开发者ID:foozmeat,项目名称:Wheelbuilder,代码行数:36,代码来源:app.py

示例8: send_mail

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def send_mail(app, form):
    """
    Send email confirmation of an RSVP response,
    both to myself and to the guest. If DEBUG
    is enabled, send responses to a testing
    address instead.
    """
    mail = Mail(app)

    msg = Message("Thanks for your RSVP!",
        sender="[email protected]",
        reply_to="Daven and Beth <[email protected]>",
        extra_headers={"From":"Daven and Beth via davenquinn.com <[email protected]>"})

    if app.config["DEBUG"]:
        msg.recipients = ['[email protected]']
    else:
        msg.recipients = [form["email"]]
        msg.bcc = ["[email protected]"]

    _ = partial(render_template,
        form=form,
        attending=int(form["number"]) > 0)

    msg.body = _("wedding/email/thanks.txt")
    msg.html = _("wedding/email/thanks.html")
    mail.send(msg)
开发者ID:davenquinn,项目名称:wedding-website,代码行数:29,代码来源:rsvp.py

示例9: registration_user

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def registration_user():
    data = request.get_json(force=True)
    if not User().check_mail_for_uniqueness(data['email']):
        return hook_validation_error('Email already exists. Please register with a new email.')
    elif not User().check_unique_username(data['username']):
        return hook_validation_error('Username already exists, please try another username')
    else:
        user = datastore.create_user(email=data['email'], password=data['password'])
        user.set_password(data['password'])
        user.active = False
        user.username = data['username']
        db.session.commit()

    email_token = generate_confirmation_token(user.email)
    confirm_url = url_for('.confirm_email', token=email_token, _external=True)

    mail = Mail()
    msg = Message("Please confirm your account", sender="[email protected]", recipients=[user.email])
    msg.body = render_template(
        "email/confirmation_email.txt",
        confirmation_url=confirm_url,
        user=user
    )
    msg.html = render_template(
        "email/confirmation_email.html",
        confirmation_url=confirm_url,
        user=user
    )
    mail.send(msg)

    return jsonify({
        'id': user.id,
        'message': 'User successfully created, please check your email to activate your account'
    })
开发者ID:darrenmcc,项目名称:Flask-Restless-Restangular-with-JWT-auth,代码行数:36,代码来源:views.py

示例10: reset

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def reset():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = EmailForm()
    if form.validate_on_submit():
        agency = Agency.query.filter_by(email=form.email.data).first_or_404()

        subject = "Password reset requested."

        token = ts.dumps(agency.email, salt='recover-key')

        recover_url = url_for('reset_with_token', token=token, _external=True)

        html = 'hello ' + recover_url

        from flask_mail import Mail, Message

        mail = Mail()
        mail.init_app(app)
        msg = Message("hello",
                      sender="[email protected]",
                      recipients=["[email protected]"])
        msg.html = html
        mail.send(msg)
        flash('An email has been sent to ' + agency.email +
              ' with a password reset link.')
        return redirect(url_for("login"))
    return render_template('reset.html', form=form)
开发者ID:roberttstephens,项目名称:not_uniformity,代码行数:30,代码来源:views.py

示例11: execute

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
    def execute(self, **kwargs):
        """
        Send email message
        """
        from . import actions
        with self.act_manager.app.app_context():
            if self.act_manager.app.debug == True:
                msg = Message(sender='[email protected]')
            for func in [getattr(self, aa) for aa in dir(self) if aa.startswith('get_')]:
                result = func(**kwargs)
                if result:
                    head, sep, tail = func.__name__.partition('_')
                    if tail == 'attachments':
                        for attachment in result:
                            msg.add_attachment(attachment)
                    else:
                        setattr(msg, tail, result)

            mail = Mail(self.act_manager.app)
            mail.connect()
            mail.send(msg)
            if self.log_mail:
                """
                Log email to a table with a timestamp. Note, for attachements, don't only log the
                file name and content_type, not the data.
                """
                pass
        return
开发者ID:harvardinformatics,项目名称:iggybase,代码行数:30,代码来源:actions.py

示例12: Email

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
class Email(object):

    def __init__(self, app):
        self.app = app
        self.mail = Mail(app)

    def send_welcome(self, user, passwd):
        subject = 'Bem vindo ao garupa.com!'
        recipients = [user.get_email()]
        body = 'Oi %s,\n' % user.get_name()
        body += 'Sua conta no garupa.com foi criada com sucesso!\n\n'
        body += 'Sua matricula: %s\n' % user.get_uid()
        body += 'Sua senha: %s (nao va perder em?)\n' % passwd
        self.send(subject, recipients, body)

    def send_recover_passwd(self, user, passwd):
        subject = 'Tua senha! Criatura esquecida!'
        recipients = [user.get_email()]
        body = 'Oi %s,\n' % user.get_name()
        body += 'Esquecesse tua senha num foi?\n'
        body += 'Sua senha nova: %s (nao vai esquecer de novo em?)' % passwd
        self.send(subject, recipients, body)

    def send(self, subject, recipients, text_body):
        msg = Message(subject, recipients=recipients)
        msg.body = text_body
        thr = Thread(target=self.send_async, args=[msg])
        thr.start()

    def send_async(self, msg):
        with self.app.app_context():
            self.mail.send(msg)
开发者ID:mari-linhares,项目名称:garupa.com,代码行数:34,代码来源:mailing.py

示例13: send_mail

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def send_mail(to, subject, fro=None, template_name=None, bcc=None, files=None, msg_body=None, **template_params):
    bcc = [] if bcc is None else bcc
    files = [] if files is None else files

    # ensure that email isn't sent if it is disabled
    #if not app.config.get("ENABLE_EMAIL", False):
     #   return

    assert type(to) == list
    assert type(files) == list
    if bcc and not isinstance(bcc, list):
        bcc = [bcc]

    #if app.config.get('CC_ALL_EMAILS_TO', None) is not None:
     #   bcc.append(app.config.get('CC_ALL_EMAILS_TO'))

    # ensure everything is unicode
    unicode_params = {}
    for k, v in template_params.iteritems():
        unicode_params[k] = to_unicode(v)

    # Get the body text from the msg_body parameter (for a contact form),
    # or render from a template.
    # TODO: This could also find and render an HTML template if present
    appcontext = True
    if msg_body:
        plaintext_body = msg_body
    else:
        try:
            plaintext_body = render_template(template_name, **unicode_params)
        except:
            appcontext = False
            with app.test_request_context():
                plaintext_body = render_template(template_name, **unicode_params)

    if fro is None:
        fro = app.config.get("MAIL_FROM_ADDRESS")

    # create a message
    msg = Message(subject=subject,
                  recipients=to,
                  body=plaintext_body,
                  html=None,
                  sender=fro,
                  cc=None,
                  bcc=bcc,
                  attachments=files,
                  reply_to=None,
                  date=None,
                  charset=None,
                  extra_headers=None
    )

    if appcontext:
        mail = Mail(app)
        mail.send(msg)
    else:
        with app.test_request_context():
            mail = Mail(app)
            mail.send(msg)
开发者ID:richard-jones,项目名称:magnificent-octopus,代码行数:62,代码来源:mail.py

示例14: test_email

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def test_email():
    from flask_mail import Mail, Message
    mail = Mail(app)
    msg = Message(subject='test subject', recipients=[app.config['TEST_RECIPIENT']])
    msg.body = 'text body'
    msg.html = '<b>HTML</b> body'
    with app.app_context():
        mail.send(msg)
开发者ID:muminoff,项目名称:flask-skeleton,代码行数:10,代码来源:manage.py

示例15: send_mail

# 需要导入模块: from flask_mail import Mail [as 别名]
# 或者: from flask_mail.Mail import send [as 别名]
def send_mail(config, msg):
    if not config.get("DEFAULT_MAIL_SENDER", None):
        return
    app = Flask("yuan")
    app.config = config
    with app.test_request_context():
        mail = Mail(app)
        mail.send(msg)
开发者ID:hipeace86,项目名称:june,代码行数:10,代码来源:mail.py


注:本文中的flask_mail.Mail.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。