Ejemplo n.º 1
0
def notify_new_order_to_admin_by_email(order_state, request):
    admin_email = Config.get_string_value('config.admin_email')
    if admin_email != None and admin_email != '':
        localizer = get_localizer(request)

        # Create the body of the message (a plain-text and an HTML version).
        text_ts = _('plain_new_order_admin_mail',
            mapping={'name': order_state.order.user.name,
                     'login': order_state.order.user.login,
                     'units': order_state.order.units,
                     'address': order_state.order.address,
                     'url': request.route_url('orders'),
                     'state': _('order_state_0',
                                domain='Ondestán')},
            domain='Ondestan')
        html_ts = _('html_new_order_admin_mail',
            mapping={'name': order_state.order.user.name,
                     'login': order_state.order.user.login,
                     'units': order_state.order.units,
                     'address': order_state.order.address,
                     'url': request.route_url('orders'),
                     'state': _('order_state_0',
                                domain='Ondestán')},
            domain='Ondestan')
        subject_ts = _('subject_new_order_admin_mail', domain='Ondestan')

        text = localizer.translate(text_ts)
        html = localizer.translate(html_ts)
        subject = localizer.translate(subject_ts)

        send_mail(html, text, subject, admin_email)
Ejemplo n.º 2
0
    def __init__(self):
        host = expandvars(Config.get_string_value('db.host'))
        port = expandvars(Config.get_string_value('db.port'))
        db = expandvars(Config.get_string_value('db.dbname'))
        user = expandvars(Config.get_string_value('db.user'))
        password = expandvars(Config.get_string_value('db.password'))

        conn_str = 'postgresql+psycopg2://' + user + ':' + password + \
                         '@' + host + ':' + port + '/' + db
        self.engine = create_engine(
            conn_str,
            echo=True
        )

        Session = sessionmaker(bind=self.engine)

        self.session = Session()

        ## Create all Tables

        Base.metadata.create_all(self.engine)
Ejemplo n.º 3
0
def send_mail(html, text, subject, destination):

    smtp_server = Config.get_string_value('smtp.server')
    smtp_port = Config.get_int_value('smtp.port')
    smtp_mail = Config.get_string_value('smtp.mail')
    smtp_password = Config.get_string_value('smtp.password')

    # Create message container - the correct MIME type is multipart/alternative
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = smtp_mail
    msg['To'] = destination

    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(text, 'plain', 'UTF-8')
    part2 = MIMEText(html, 'html', 'UTF-8')

    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)

    server = SMTP(smtp_server, smtp_port)
    server.starttls()

    #Next, log in to the server
    server.login(smtp_mail, smtp_password)

    #Send the mail
    # sendmail function takes 3 arguments:
    # sender's address
    # recipient's address
    # and message to send - here it is sent as one string.
    server.sendmail(smtp_mail, destination, msg.as_string())
    server.quit()