Esempio n. 1
0
def mailto_user_list( data ):

#    logging.debug('send mail to %s' % data)

    UID_LIST = data.get('ID_LIST', [])
    uid = data.get('uid', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(
        db, 'notice.smtp.fromaddr', 'admin@localhost')

    job = SiteJob( uid, _('send mail to user list.') )
    job.set_started()
    db.add( job )
    db.commit()

    # send mail
    qm = QueMail.get_instance()

    if UID_LIST:
        USER_LIST = []
        for ID in UID_LIST:
            U = db.query(User).get( ID )
            if U:
                USER_LIST.append( U )
    else:
        USER_LIST = db.query(User)

    for U in USER_LIST:

        text = _('send mail to %s: %s (%s)') % (U.id, U.username, U.email)

        logging.debug( text )

        job.update_status( text )
        db.commit()

        time.sleep(1)

        if not (U and U.email and U.email_valid):
            continue

        d = { 'subject': subject, 'BODY_HTML': body,
              'username': U.nickname if U.nickname else U.username }
        body = render_template('custom/mail_template.html', **d)

        if body:

            e = Email( subject = subject, text = body,
                       adr_to = U.email,
                       adr_from = adr_from, mime_type = 'html' )

#            qm.send( e )

        else:
            logging.error( _('render email body for html failed.') )

    job.set_ended()
    db.commit()
Esempio n. 2
0
def init_quemail():

    qm = QueMail.get_instance()

    smtp_server = SiteConfig.get(db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(db, 'notice.smtp.port', 25))
    smtp_username = SiteConfig.get(db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(db, 'notice.smtp.password', None)

    print 'smtp_server   = ', smtp_server
    print 'smtp_port     = ', smtp_port
    print 'smtp_username = '******'smtp_password = ', smtp_password

    qm.init(smtp_server, smtp_username, smtp_password, smtp_port=smtp_port)

    qm.start()
Esempio n. 3
0
def exit_handler(_signal, frame):

    if _signal == signal.SIGINT:
        print " ... You Pressed CTL+C, exit ... "

    elif _signal == signal.SIGHUP:
        print " ... get SIGHUP, exit ... "

    if _signal == signal.SIGTERM:
        print " ... get SIGTERM, exit ... "


#    db.dispose()

# TODO: quit email
    try:
        qm = QueMail.get_instance()
        qm.end()
    except RuntimeError:
        pass

    sys.exit(1)
Esempio n. 4
0
def init_quemail():

    qm = QueMail.get_instance()

    smtp_server = SiteConfig.get(
        db, 'notice.smtp.server', '127.0.0.1')
    smtp_port = int(SiteConfig.get(
            db, 'notice.smtp.port', 25 ))
    smtp_username = SiteConfig.get(
        db, 'notice.smtp.username', None)
    smtp_password = SiteConfig.get(
        db, 'notice.smtp.password', None)

    print 'smtp_server   = ', smtp_server
    print 'smtp_port     = ', smtp_port
    print 'smtp_username = '******'smtp_password = ', smtp_password

    qm.init( smtp_server, smtp_username, smtp_password,
             smtp_port = smtp_port )

    qm.start()
Esempio n. 5
0
def exit_handler(_signal, frame):

    if _signal == signal.SIGINT:
        print " ... You Pressed CTL+C, exit ... "

    elif _signal == signal.SIGHUP:
        print " ... get SIGHUP, exit ... "

    if _signal == signal.SIGTERM:
        print " ... get SIGTERM, exit ... "


#    db.dispose()

    # TODO: quit email
    try:
        qm = QueMail.get_instance()
        qm.end()
    except RuntimeError:
        pass

    sys.exit(1)
Esempio n. 6
0
def mailto_address(data):

    to = data.get('to', None)
    to_user_id = data.get('to_user_id', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(db, 'notice.smtp.fromaddr', 'admin@localhost')

    if not (to or to_user_id):
        logging.error(_('mailto_address: no address find'))
        return

    qm = QueMail.get_instance()

    if to:
        username = to.split('@')[0]

    if to_user_id:
        U = db.query(User).get(to_user_id)
        if U:
            username = U.nickname if U.nickname else U.username
            to = U.email

    d = {'subject': subject, 'BODY_HTML': body, 'username': username}

    body = render_template('custom/mail_template.html', **d)

    if body:
        e = Email(subject=subject,
                  text=body,
                  adr_to=to,
                  adr_from=adr_from,
                  mime_type='html')
        qm.send(e)

    else:
        logging.error(_('render email body for html failed.'))
Esempio n. 7
0
def mailto_address( data ):

    to = data.get('to', None)
    to_user_id = data.get('to_user_id', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(
        db, 'notice.smtp.fromaddr', 'admin@localhost')

    if not (to or to_user_id):
        logging.error( _('mailto_address: no address find') )
        return

    qm = QueMail.get_instance()

    if to:
        username = to.split('@')[0]

    if to_user_id:
        U = db.query(User).get( to_user_id )
        if U:
            username = U.nickname if U.nickname else U.username
            to = U.email

    d = { 'subject': subject, 'BODY_HTML': body,
          'username': username }

    body = render_template('custom/mail_template.html', **d)

    if body:
        e = Email( subject = subject, text = body,
                   adr_to = to,
                   adr_from = adr_from, mime_type = 'html' )
        qm.send( e )

    else:
        logging.error( _('render email body for html failed.') )
Esempio n. 8
0
def mailto_user_list(data):

    #    logging.debug('send mail to %s' % data)

    UID_LIST = data.get('ID_LIST', [])
    uid = data.get('uid', None)
    subject = data.get('subject', None)
    body = data.get('body', None)
    adr_from = SiteConfig.get(db, 'notice.smtp.fromaddr', 'admin@localhost')

    job = SiteJob(uid, _('send mail to user list.'))
    job.set_started()
    db.add(job)
    db.commit()

    # send mail
    qm = QueMail.get_instance()

    if UID_LIST:
        USER_LIST = []
        for ID in UID_LIST:
            U = db.query(User).get(ID)
            if U:
                USER_LIST.append(U)
    else:
        USER_LIST = db.query(User)

    for U in USER_LIST:

        text = _('send mail to %s: %s (%s)') % (U.id, U.username, U.email)

        logging.debug(text)

        job.update_status(text)
        db.commit()

        time.sleep(1)

        if not (U and U.email and U.email_valid):
            continue

        d = {
            'subject': subject,
            'BODY_HTML': body,
            'username': U.nickname if U.nickname else U.username
        }
        body = render_template('custom/mail_template.html', **d)

        if body:

            e = Email(subject=subject,
                      text=body,
                      adr_to=U.email,
                      adr_from=adr_from,
                      mime_type='html')


#            qm.send( e )

        else:
            logging.error(_('render email body for html failed.'))

    job.set_ended()
    db.commit()