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


Python flask_mail.Message方法代码示例

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


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

示例1: send_deletion_notification

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_deletion_notification(username, email, delete_reason):
    """
    Send an email to notify that an account has been deleted.
    """
    refresh_email_settings()
    settings = api.config.get_settings()

    body = settings["email"]["deletion_notification_body"].format(
        competition_name=settings["competition_name"],
        username=username,
        delete_reason=delete_reason,
    )

    subject = "{} Account Deletion".format(settings["competition_name"])

    message = Message(body=body, recipients=[email], subject=subject)
    mail.send(message) 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:19,代码来源:email.py

示例2: send_mail

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_mail(
        self, template, subject, recipient, sender, body, html, user, **kwargs
    ):
        """Send an email via the Flask-Mail extension.

        :param template: the Template name. The message has already been rendered
            however this might be useful to differentiate why the email is being sent.
        :param subject: Email subject
        :param recipient: Email recipient
        :param sender: who to send email as (see :py:data:`SECURITY_EMAIL_SENDER`)
        :param body: the rendered body (text)
        :param html: the rendered body (html)
        :param user: the user model
        """

        from flask_mail import Message

        msg = Message(subject, sender=sender, recipients=[recipient])
        msg.body = body
        msg.html = html

        mail = current_app.extensions.get("mail")
        mail.send(msg) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:25,代码来源:mail_util.py

示例3: send_email

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_email(subject, body, recipient_email, html=None):
    """
    Send an email with given subject and body to given recipient.
    """
    if html is None:
        html = body
    with app.app_context():
        mail_default_sender = app.config["MAIL_DEFAULT_SENDER"]
        message = Message(
            sender="Kitsu Bot <%s>" % mail_default_sender,
            body=body,
            html=html,
            subject=subject,
            recipients=[recipient_email]
        )
        mail.send(message) 
开发者ID:cgwire,项目名称:zou,代码行数:18,代码来源:emails.py

示例4: send_verification_email

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_verification_email(user):
    """Send verification email to user
    """
    # create email verification request
    r = EmailVerificationRequest(key=os.urandom(32).hex(), user=user)
    db.session.add(r)
    db.session.flush()

    # send email
    subject = 'Flaskapp Account: Please Confirm Email'
    msg = Message(subject, recipients=[user.email])
    verify_url = url_for('.verify_email', key=r.key, email=user.email, \
                             _external=True)

    f = '/auth/verify-email-email'
    msg.body = render_template(f + '.txt', verify_url=verify_url)

    html = render_template(f + '.html', verify_url=verify_url)
    base_url = url_for('content.home', _external=True)
    msg.html = transform(html, base_url=base_url)
    mail.send(msg) 
开发者ID:muicss,项目名称:flaskapp,代码行数:23,代码来源:auth.py

示例5: send_mail

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_mail(category_id, category_name):
    with app.app_context():
        category = Category(category_name)
        category.id = category_id
        message = Message(
            "New category added",
            recipients=['some-receiver@domain.com']
        )
        message.body = render_template(
            "category-create-email-text.html",
            category=category
        )
        message.html = render_template(
            "category-create-email-html.html",
            category=category
        )
        mail.send(message) 
开发者ID:PacktPublishing,项目名称:Flask-Framework-Cookbook-Second-Edition,代码行数:19,代码来源:views.py

示例6: sendVerifyEmail

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def sendVerifyEmail(newEmail, token):
	print("Sending verify email!")
	msg = Message("Verify email address", recipients=[newEmail])

	msg.body = """
			This email has been sent to you because someone (hopefully you)
			has entered your email address as a user's email.

			If it wasn't you, then just delete this email.

			If this was you, then please click this link to verify the address:

			{}
		""".format(abs_url_for('users.verify_email', token=token))

	msg.html = render_template("emails/verify.html", token=token)
	mail.send(msg) 
开发者ID:minetest,项目名称:contentdb,代码行数:19,代码来源:emails.py

示例7: email_exception

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def email_exception(exception):
    '''Handles the exception message from Flask by sending an email to the
    recipients defined in config.ADMINS
    '''

    msg = Message("[AGA Online Ratings|Flask] Exception: %s" % exception.__class__.__name__,
                    recipients=current_app.config['ADMINS'])
    msg_contents = [
        'Traceback:',
        '='*80,
        traceback.format_exc(),
    ]
    msg_contents.append('\n')
    msg_contents.append('Request Information:')
    msg_contents.append('='*80)
    for k, v in sorted(request.environ.items()):
        msg_contents.append('%s: %s' % (k, v))

    msg.body = '\n'.join(msg_contents) + '\n'

    mail = current_app.extensions.get('mail')
    mail.send(msg) 
开发者ID:usgo,项目名称:online-ratings,代码行数:24,代码来源:error_mail.py

示例8: reset_passwd_request

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def reset_passwd_request():
    if 'email' not in request.json:
        return error_response(errors.AUTH_EMAIL_MISSING, 400)
    email = request.json['email']
    user = User.query.filter_by(email=email).first()
    if not user:
        return error_response(errors.AUTH_NOT_FOUND.format(email), 404)
    hashstr = hashlib.sha1(str(random.getrandbits(128)) + user.email).hexdigest()
    # Deactivate all other password resets for this user.
    PasswdReset.query.filter_by(user=user).update({'active': False})
    reset = PasswdReset(hashstr=hashstr, active=True, user=user)
    db.session.add(reset)
    db.session.commit()
    # Send password reset email to user.
    from mhn import mhn
    msg = Message(
            html=reset.email_body, subject='MHN Password reset',
            recipients=[user.email], sender=mhn.config['DEFAULT_MAIL_SENDER'])
    try:
        mail.send(msg)
    except:
        return error_response(errors.AUTH_SMTP_ERROR, 500)
    else:
        return jsonify({}) 
开发者ID:CommunityHoneyNetwork,项目名称:CHN-Server,代码行数:26,代码来源:views.py

示例9: send_via_ses

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_via_ses(subject, body, targets):
    """
    Attempts to deliver email notification via SMTP.
    :param subject:
    :param body:
    :param targets:
    :return:
    """
    client = boto3.client("ses", region_name="us-east-1")
    client.send_email(
        Source=current_app.config.get("LEMUR_EMAIL"),
        Destination={"ToAddresses": targets},
        Message={
            "Subject": {"Data": subject, "Charset": "UTF-8"},
            "Body": {"Html": {"Data": body, "Charset": "UTF-8"}},
        },
    ) 
开发者ID:Netflix,项目名称:lemur,代码行数:19,代码来源:plugin.py

示例10: send_email

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def send_email(recipient, subject, html_message, text_message):
    """ Send email from default sender to 'recipient' """
    # Make sure that Flask-Mail has been initialized
    mail_engine = mail
    if not mail_engine:
        return 'Flask-Mail has not been initialized. Initialize Flask-Mail or disable USER_SEND_PASSWORD_CHANGED_EMAIL, USER_SEND_REGISTERED_EMAIL and USER_SEND_USERNAME_CHANGED_EMAIL'

    try:

        # Construct Flash-Mail message
        message = Message(subject,
                          recipients=[recipient],
                          html=html_message,
                          body=text_message)
        return mail.send(message)

    # Print helpful error messages on exceptions
    except (socket.gaierror, socket.error) as e:
        return 'SMTP Connection error: Check your MAIL_SERVER and MAIL_PORT settings.'
    except smtplib.SMTPAuthenticationError:
        return 'SMTP Authentication error: Check your MAIL_USERNAME and MAIL_PASSWORD settings.' 
开发者ID:meolu,项目名称:walle-web,代码行数:23,代码来源:emails.py

示例11: get_message_plain_text

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def get_message_plain_text(msg: Message):
    """
    Converts an HTML message to plain text.

    :param msg: A :class:`~flask_mail.Message`
    :return: The plain text message.
    """
    if msg.body:
        return msg.body

    if BeautifulSoup is None or not msg.html:
        return msg.html

    plain_text = '\n'.join(line.strip() for line in
                           BeautifulSoup(msg.html, 'lxml').text.splitlines())
    return re.sub(r'\n\n+', '\n\n', plain_text).strip() 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:18,代码来源:utils.py

示例12: _send_mail

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def _send_mail(subject_or_message: Optional[Union[str, Message]] = None,
               to: Optional[Union[str, List[str]]] = None,
               template: Optional[str] = None,
               **kwargs):
    """
    The default function used for sending emails.

    :param subject_or_message: A subject string, or for backwards compatibility with
                               stock Flask-Mail, a :class:`~flask_mail.Message` instance
    :param to: An email address, or a list of email addresses
    :param template: Which template to render.
    :param kwargs: Extra kwargs to pass on to :class:`~flask_mail.Message`
    """
    subject_or_message = subject_or_message or kwargs.pop('subject')
    to = to or kwargs.pop('recipients', [])
    msg = make_message(subject_or_message, to, template, **kwargs)
    with mail.connect() as connection:
        connection.send(msg) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:20,代码来源:utils.py

示例13: test_bad_multiline_subject

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def test_bad_multiline_subject(self):
        msg = Message(subject="testing\r\n testing\r\n ",
                      sender="from@example.com",
                      body="testing",
                      recipients=["to@example.com"])
        self.assertRaises(BadHeaderError, self.mail.send, msg)

        msg = Message(subject="testing\r\n testing\r\n\t",
                      sender="from@example.com",
                      body="testing",
                      recipients=["to@example.com"])
        self.assertRaises(BadHeaderError, self.mail.send, msg)

        msg = Message(subject="testing\r\n testing\r\n\n",
                      sender="from@example.com",
                      body="testing",
                      recipients=["to@example.com"])
        self.assertRaises(BadHeaderError, self.mail.send, msg) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:20,代码来源:test_upstream.py

示例14: test_unicode_headers

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def test_unicode_headers(self):
        msg = Message(subject="subject",
                      sender=u'ÄÜÖ → ✓ <from@example.com>',
                      recipients=[u"Ä <t1@example.com>",
                                  u"Ü <t2@example.com>"],
                      cc=[u"Ö <cc@example.com>"])

        response = msg.as_string()
        a1 = sanitize_address(u"Ä <t1@example.com>")
        a2 = sanitize_address(u"Ü <t2@example.com>")
        h1_a = Header("To: %s, %s" % (a1, a2))
        h1_b = Header("To: %s, %s" % (a2, a1))
        a3 = sanitize_address(u"ÄÜÖ → ✓ <from@example.com>")
        h2 = Header("From: %s" % a3)
        h3 = Header("Cc: %s" % sanitize_address(u"Ö <cc@example.com>"))

        # Ugly, but there's no guaranteed order of the recipients in the header
        try:
            self.assertIn(h1_a.encode(), response)
        except AssertionError:
            self.assertIn(h1_b.encode(), response)

        self.assertIn(h2.encode(), response)
        self.assertIn(h3.encode(), response) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:26,代码来源:test_upstream.py

示例15: test_sendmail_with_ascii_recipient

# 需要导入模块: import flask_mail [as 别名]
# 或者: from flask_mail import Message [as 别名]
def test_sendmail_with_ascii_recipient(self):
        with self.mail.connect() as conn:
            with mock.patch.object(conn, 'host') as host:
                msg = Message(subject="testing",
                              sender="from@example.com",
                              recipients=["to@example.com"],
                              body="testing")
                conn.send(msg)

                host.sendmail.assert_called_once_with(
                    "from@example.com",
                    ["to@example.com"],
                    msg.as_bytes(),
                    msg.mail_options,
                    msg.rcpt_options
                ) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:18,代码来源:test_upstream.py


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