Beispiel #1
0
    def __init__(self, app, sender_email=None, sender_name=None):
        """Check config settings and setup Flask-Sendemail.

        Args:
            app(Flask): The Flask application instance.
        """

        super(SendmailEmailAdapter, self).__init__(app)

        # Setup Flask-Mail
        try:
            from flask_sendmail import Mail
        except ImportError:
            raise ConfigError(
                "The Flask-Sendmail package is missing. Install Flask-Sendmail with 'pip install Flask-Sendmail'."
            )
        self.mail = Mail(app)
Beispiel #2
0
class SendmailEmailAdapter(EmailAdapterInterface):
    """ Implements the EmailAdapter interface to send emails with sendmail using Flask-Sendmail."""
    def __init__(self, app, sender_email=None, sender_name=None):
        """Check config settings and setup Flask-Sendemail.

        Args:
            app(Flask): The Flask application instance.
        """

        super(SendmailEmailAdapter, self).__init__(app)

        # Setup Flask-Mail
        try:
            from flask_sendmail import Mail
        except ImportError:
            raise ConfigError(
                "The Flask-Sendmail package is missing. Install Flask-Sendmail with 'pip install Flask-Sendmail'."
            )
        self.mail = Mail(app)

    def send_email_message(self, recipient, subject, html_message,
                           text_message, sender_email, sender_name):
        """ Send email message via Flask-Sendmail.

        Args:
            recipient: Email address or tuple of (Name, Email-address).
            subject: Subject line.
            html_message: The message body in HTML.
            text_message: The message body in plain text.
        """

        if not current_app.testing:  # pragma: no cover

            # Prepare email message
            from flask_sendmail import Message
            message = Message(subject,
                              recipients=[recipient],
                              html=html_message,
                              body=text_message)

            # Send email message
            self.mail.send(message)
Beispiel #3
0
    def setUp(self):

        self.app = Flask(__name__)
        self.app.config.from_object(self)

        self.assertTrue(self.app.testing)

        self.mail = Mail(self.app)

        self.ctx = self.app.test_request_context()
        self.ctx.push()
class SendmailEmailAdapter(EmailAdapterInterface):
    """ Implements the EmailAdapter interface to send emails with sendmail using Flask-Sendmail."""
    def __init__(self, app, sender_email=None, sender_name=None):
        """Check config settings and setup Flask-Sendemail.

        Args:
            app(Flask): The Flask application instance.
        """

        super(SendmailEmailAdapter, self).__init__(app)

        # Setup Flask-Mail
        try:
            from flask_sendmail import Mail
        except ImportError:
            raise ConfigError(
                "The Flask-Sendmail package is missing. Install Flask-Sendmail with 'pip install Flask-Sendmail'.")
        self.mail = Mail(app)

    def send_email_message(self, recipient, subject, html_message, text_message, sender_email, sender_name):
        """ Send email message via Flask-Sendmail.

        Args:
            recipient: Email address or tuple of (Name, Email-address).
            subject: Subject line.
            html_message: The message body in HTML.
            text_message: The message body in plain text.
        """

        if not current_app.testing:  # pragma: no cover

            # Prepare email message
            from flask_sendmail import Message
            message = Message(
                subject,
                recipients=[recipient],
                html=html_message,
                body=text_message)

            # Send email message
            self.mail.send(message)
    def __init__(self, app, sender_email=None, sender_name=None):
        """Check config settings and setup Flask-Sendemail.

        Args:
            app(Flask): The Flask application instance.
        """

        super(SendmailEmailAdapter, self).__init__(app)

        # Setup Flask-Mail
        try:
            from flask_sendmail import Mail
        except ImportError:
            raise ConfigError(
                "The Flask-Sendmail package is missing. Install Flask-Sendmail with 'pip install Flask-Sendmail'.")
        self.mail = Mail(app)
Beispiel #6
0
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_wtf import CSRFProtect
from flask_sendmail import Mail

from globals import logging, config

db_path = config.get('db_path')
db = SQLAlchemy()

mail = Mail()


def init_app(app, create=False, multi_thread=True):
    app.config['SECRET_KEY'] = config.get('SECRET_KEY')
    app.config['SQLALCHEMY_DATABASE_URI'] = db_path + (
        '' if multi_thread else '?check_same_thread=False')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    Bootstrap(app)
    CSRFProtect(app)
    logging.log_init(app)
    mail.init_app(app)
    db.init_app(app)

    if create:
        db.create_all(app=app)
Beispiel #7
0
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from itsdangerous import URLSafeTimedSerializer
from flask_sendmail import Mail, Message
from flask_marshmallow import Marshmallow

app = Flask(__name__)
app.config['SECRET_KEY'] = 'Thisissecretkey'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////flaskdemo/database.db'
app.config['MAIL_DEFAULT_SENDER'] = '*****@*****.**'
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
mail = Mail(app)
ma = Marshmallow(app)


class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(15), unique=True)
    email = db.Column(db.String(50), unique=True)
    password = db.Column(db.String(80))
    firstname = db.Column(db.String(20))
    lastname = db.Column(db.String(20))
    phonenumber = db.Column(db.String(10))


class UserSchema(ma.Schema):
    class Meta: