Example #1
0
    def mail_notice(self, email, K):

        host = SiteConfig.get(
            self.db, 'site.host', 'http://127.0.0.1')

        adr_from = SiteConfig.get(self.db, 'notice.smtp.fromaddr',
                                  'localhost@localhost')

        subject = _('[ LuoYunCloud ] Validate your email address.')

        validate_url = host + self.reverse_url('account:email:validate')
        validate_url += "?auth_key=%s" % K.auth_key

        d = { 'return_string': True,
              'validate_url': validate_url }

        body = self.render('account/email_validate_notice.html', **d)

        response = self.sendmsg(
            uri = 'mailto.address',
            data = { 'to': email,
                     'subject': subject,
                     'body': body } )

        return response
Example #2
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.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)

    mail_dir = SiteConfig.get(db, 'site.send_mail.dir',
                              '/opt/LuoYun/run/email/')

    dbsession.remove()

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

    if fm.init(smtp_server,
               smtp_username,
               smtp_password,
               smtp_port=smtp_port,
               store_path=mail_dir):
        logging.info('FileSysMail init success.')
        fm.start()
        return True

    else:
        logging.error('FileSysMail init failed.')
        return False
Example #3
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.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)

    mail_dir = SiteConfig.get(
        db, 'site.send_mail.dir', '/opt/LuoYun/run/email/')

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

    fm.init( smtp_server, smtp_username, smtp_password,
             smtp_port = smtp_port, store_path = mail_dir )

    fm.start()

    dbsession.remove()
Example #4
0
def mailto_address(data):

    data = data.get('msg', {})
    #    logging.debug('mailto_address: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    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

    mail_total = SiteConfig.get(db, 'site.send_mail.total', 0)
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key='site.send_mail.total').first()

    fm = FileSysMail.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
            if not to:
                logging.error(
                    _('mailto_address: %s(%s) have not email address') %
                    (username, U.id))
                return

    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')

        mail_total.value = int(mail_total.value) + 1
        fm.send(e, '%s-mail' % mail_total.value)

    else:
        logging.error(_('render email body for html failed.'))
Example #5
0
def mailto_address( data ):

    data = data.get('msg', {})
#    logging.debug('mailto_address: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    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

    mail_total = SiteConfig.get( db, 'site.send_mail.total', 0 )
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key = 'site.send_mail.total').first()

    fm = FileSysMail.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
            if not to:
                logging.error( _('mailto_address: %s(%s) have not email address') % (username, U.id) )
                return


    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' )

        mail_total.value = int(mail_total.value) + 1
        fm.send( e, '%s-mail' % mail_total.value )

    else:
        logging.error( _('render email body for html failed.') )
def init_account(user, db):

    from app.site.utils import get_site_config_int
    from app.resource.models import Resource
    from app.auth.models import Group
    from app.site.models import SiteConfig
    from app.account.models import UserProfile

    logging.debug('Init account "%s".' % user.username)

    now = datetime.datetime.now()
    expired_date = now + datetime.timedelta(seconds=365 * 3600 * 24)

    # default resource
    cpu = get_site_config_int('user.default.dynamic_cpu', 0)
    memory = get_site_config_int('user.default.dynamic_memory', 0)
    storage = get_site_config_int('user.default.dynamic_storage', 0)
    instance = get_site_config_int('user.default.dynamic_instance', 0)

    for t, s in [(Resource.T_CPU, cpu), (Resource.T_MEMORY, memory),
                 (Resource.T_STORAGE, storage),
                 (Resource.T_INSTANCE, instance)]:

        print 's = "%s"' % s
        if not s: continue

        r = Resource(user=user,
                     rtype=t,
                     size=s,
                     effect_date=now,
                     expired_date=expired_date)

        db.add(r)

    # default profile
    profile = db.query(UserProfile).filter_by(user_id=user.id).first()

    if not profile:
        # create user profile
        profile = UserProfile(user)
        db.add(profile)
        db.commit()

    language_id = SiteConfig.get(db, 'user.default.language', 61)
    user.language_id = language_id

    # default group
    gid = SiteConfig.get(db, 'user.default.group', 2)
    g = db.query(Group).get(gid)
    if g:
        user.groups = [g]

    db.commit()
def init_account(user, db):

    from app.site.utils import get_site_config_int
    from app.resource.models import Resource
    from app.auth.models import Group
    from app.site.models import SiteConfig
    from app.account.models import UserProfile

    logging.debug('Init account "%s".' % user.username)

    now = datetime.datetime.now()
    expired_date = now + datetime.timedelta(seconds=365 * 3600 * 24)

    # default resource
    cpu = get_site_config_int("user.default.dynamic_cpu", 0)
    memory = get_site_config_int("user.default.dynamic_memory", 0)
    storage = get_site_config_int("user.default.dynamic_storage", 0)
    instance = get_site_config_int("user.default.dynamic_instance", 0)

    for t, s in [
        (Resource.T_CPU, cpu),
        (Resource.T_MEMORY, memory),
        (Resource.T_STORAGE, storage),
        (Resource.T_INSTANCE, instance),
    ]:

        print 's = "%s"' % s
        if not s:
            continue

        r = Resource(user=user, rtype=t, size=s, effect_date=now, expired_date=expired_date)

        db.add(r)

    # default profile
    profile = db.query(UserProfile).filter_by(user_id=user.id).first()

    if not profile:
        # create user profile
        profile = UserProfile(user)
        db.add(profile)
        db.commit()

    language_id = SiteConfig.get(db, "user.default.language", 61)
    user.language_id = language_id

    # default group
    gid = SiteConfig.get(db, "user.default.group", 2)
    g = db.query(Group).get(gid)
    if g:
        user.groups = [g]

    db.commit()
Example #8
0
def resource_mail_notice(hdr, user, subject=None):

    if not user:
        logging.warn('could not send notice: no user')
        return

    if not (user.email_valid and user.email and '@' in user.email):
        logging.warn('could not send notice to user(%s).' % user.id)
        return

    host = SiteConfig.get(hdr.db, 'site.host', 'http://127.0.0.1')

    if not subject:
        subject = _('[ LuoYunCloud ] Your resource has been changed')

    d = {
        'return_string': True,
        'USER': user,
        'account_url': host + hdr.reverse_url('account')
    }

    body = hdr.render('admin/user/resource_notice.html', **d)

    response = hdr.sendmsg(uri='mailto.address',
                           data={
                               'to_user_id': user.id,
                               'subject': subject,
                               'body': body
                           })
    return response
Example #9
0
    def send_mail(self, _apply):

        LID = self.language.id

        host = SiteConfig.get(
            self.db, 'site.host', 'http://127.0.0.1')

        subject = self.db.query(SiteLocaleConfig).filter(
            and_(SiteLocaleConfig.key == 'resetpass.email.subject',
                 SiteLocaleConfig.language_id == LID)).first()
        subject = subject.value if subject \
            else _('Reset your password.')

        url = host + self.reverse_url('account:resetpass') \
            + '?key=%s' % _apply.key

        d = { 'return_string': True, 'APPLY': _apply,
              'RESET_URL': url }

        body = self.render('account/reset_password_email.html', **d)

        response = self.sendmsg(
            uri = 'mailto.address',
            data = { 'to_user_id': _apply.user_id,
                     'subject': subject,
                     'body': body } )
        return response
Example #10
0
def resource_mail_notice(hdr, user, subject=None):

    if not user:
        logging.warn('could not send notice: no user')
        return

    if not (user.email_valid and user.email and '@' in user.email):
        logging.warn('could not send notice to user(%s).' % user.id)
        return

    host = SiteConfig.get(hdr.db, 'site.host', 'http://127.0.0.1')

    if not subject:
        subject = _('[ LuoYunCloud ] Your resource has been changed')

    d = { 'return_string': True, 'USER': user,
          'account_url': host + hdr.reverse_url('account') }

    body = hdr.render('admin/user/resource_notice.html', **d)

    response = hdr.sendmsg(
        uri = 'mailto.address',
        data = { 'to_user_id': user.id,
                 'subject': subject,
                 'body': body } )
    return response
Example #11
0
    def send_mail(self, _apply):

        LID = self.language.id

        host = SiteConfig.get(self.db, 'site.host', 'http://127.0.0.1')

        subject = self.db.query(SiteLocaleConfig).filter(
            and_(SiteLocaleConfig.key == 'resetpass.email.subject',
                 SiteLocaleConfig.language_id == LID)).first()
        subject = subject.value if subject \
            else _('Reset your password.')

        url = host + self.reverse_url('account:resetpass') \
            + '?key=%s' % _apply.key

        d = {'return_string': True, 'APPLY': _apply, 'RESET_URL': url}

        body = self.render('account/reset_password_email.html', **d)

        response = self.sendmsg(uri='mailto.address',
                                data={
                                    'to_user_id': _apply.user_id,
                                    'subject': subject,
                                    'body': body
                                })
        return response
Example #12
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()
Example #13
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()
Example #14
0
def update_site_config(db):

    from app.site.models import SiteConfig
    for key, value in settings.default_site_config:
        it = db.query(SiteConfig).filter_by(key=key).first()
        if it:
            print '[W] SiteConfig: key exist: %s' % key
        else:
            it = SiteConfig(key=key, value=value)
            db.add(it)
            db.commit()
Example #15
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()
Example #16
0
    def mail_notice(self, email, K):

        host = SiteConfig.get(
            self.db, 'site.host', 'http://127.0.0.1')

        adr_from = SiteConfig.get(self.db, 'notice.smtp.fromaddr',
                                  'localhost@localhost')

        subject = _('[ LuoYunCloud ] Validate your email address.')

        validate_url = host + self.reverse_url('account:email:validate')
        validate_url += "?auth_key=%s" % K.auth_key

        d = { 'return_string': True,
              'validate_url': validate_url }

        body = self.render('account/email_validate_notice.html', **d)

        e = Email( subject = subject, text = body,
                   adr_to = email,
                   adr_from = adr_from,
                   mime_type = 'html' )
        self.quemail.send( e )
Example #17
0
    def mail_notice(self, email, K):

        host = SiteConfig.get(self.db, 'site.host', 'http://127.0.0.1')

        adr_from = SiteConfig.get(self.db, 'notice.smtp.fromaddr',
                                  'localhost@localhost')

        subject = _('[ LuoYunCloud ] Validate your email address.')

        validate_url = host + self.reverse_url('account:email:validate')
        validate_url += "?auth_key=%s" % K.auth_key

        d = {'return_string': True, 'validate_url': validate_url}

        body = self.render('account/email_validate_notice.html', **d)

        response = self.sendmsg(uri='mailto.address',
                                data={
                                    'to': email,
                                    'subject': subject,
                                    'body': body
                                })

        return response
Example #18
0
def start_filesysmail():

    dbsession = orm.create_session()
    db = dbsession()

    fm = FileSysMail.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)

    mail_dir = SiteConfig.get(
        db, 'site.send_mail.dir', '/opt/LuoYun/run/email/')

    dbsession.remove()

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

    if fm.init( smtp_server, smtp_username, smtp_password,
                smtp_port = smtp_port, store_path = mail_dir ):
        logging.info('FileSysMail init success.')
        fm.start()
        return True

    else:
        logging.error('FileSysMail init failed.')
        return False
Example #19
0
def get_runtime_data(key, value=None):

    v = runtime_data.get(key)

    if v:
        return v

    db = global_dbsession()
    v = SiteConfig.get(db, key, None)

    if v:
        runtime_data[key] = v
        return v

    return value
def init_account(user, db):

    import logging, datetime

    from app.resource.models import Resource
    from app.auth.models import Group
    from app.site.models import SiteConfig
    from app.account.models import UserProfile

    logging.debug('Init account "%s".' % user.username)

    now = datetime.datetime.now()
    expired_date = now + datetime.timedelta( seconds = 365 * 3600 * 24 )

    # default resource
    cpu = SiteConfig.get(db, 'account.default.cpu', 1)
    memory = SiteConfig.get(db, 'account.default.memory', 256)
    storage = SiteConfig.get(db, 'account.default.storage', 2)
    instance = SiteConfig.get(db, 'account.default.instance', 3)

    for t, s in [
        ( Resource.T_CPU, cpu ),
        ( Resource.T_MEMORY, memory ),
        ( Resource.T_STORAGE, storage ),
        ( Resource.T_INSTANCE, instance ) ]:

        r = Resource( user = user, rtype = t, size = s,
                      effect_date = now,
                      expired_date = expired_date )

        db.add(r)

    # default profile
    profile = db.query(UserProfile).filter_by(
        user_id = user.id ).first()

    if not profile:
        # create user profile
        profile = UserProfile( user )
        db.add( profile )
        db.commit()

    # update user resource
    user.profile.update_resource_total()

    language_id = SiteConfig.get(db, 'account.default.language', 61)
    user.language_id = language_id

    # default group
    gid = SiteConfig.get(db, 'account.default.group', 2)
    g = db.query(Group).get( gid )
    if g:
        user.groups = [ g ]

    db.commit()
Example #21
0
    def post(self):

        form = self.form

        if form.validate():

            domain = json.dumps( {
                    'topdomain': form.topdomain.data,
                    'prefix': form.prefix.data,
                    'suffix': form.suffix.data } )

            if self.domain:
                self.domain.value = domain
            else:
                new = SiteConfig( key = 'domain', value = domain )
                self.db.add( new )

            self.db.commit()

            url = self.reverse_url('admin:domain')
            self.redirect( url )

        self.render()
Example #22
0
    def post(self):

        form = self.form

        if form.validate():

            nc = { 'conf_path': form.conf_path.data,
                   'log_path' : form.log_path.data,
                   'nginx'    : form.nginx.data,
                   'template' : form.template.data }

            v = json.dumps( nc )

            if self.N:
                self.N.value = v
            else:
                c = SiteConfig( 'nginx', v )
                self.db.add(c)

            self.db.commit()
            self.prepare_kwargs['saved'] = True

        self.render()
Example #23
0
    def post(self):

        Q = self.Q
        form = self.form

        if form.validate():

            v = json.dumps( { 'app_id': form.app_id.data,
                              'app_key': form.app_key.data,
                              'redirect_uri': form.redirect_uri.data,
                              'enabled': form.enabled.data } )

            if Q:
                Q.value = v
            else:
                Q = SiteConfig('qq.auth2', v)

            self.db.add(Q)
            self.db.commit()

            self.prepare_kwargs['saved'] = True

        self.render()
Example #24
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.'))
Example #25
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.') )
Example #26
0
def mailto_user_list(data):

    data = data.get('msg', {})
    #    logging.debug('mailto_user_list: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    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()

    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)

    mail_total = SiteConfig.get(db, 'site.send_mail.total', 0)
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key='site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    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_html = render_template('custom/mail_template.html', **d)

        if body_html:

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

            mail_total.value = int(mail_total.value) + 1
            fm.send(e, '%s-mail' % mail_total.value)

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

    job.set_ended()
    db.commit()
    dbsession.remove()
Example #27
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()
Example #28
0
def mailto_user_list( data ):

    data = data.get('msg', {})
#    logging.debug('mailto_user_list: data = %s' % data)

    dbsession = orm.create_session()
    db = dbsession()

    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()

    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)

    mail_total = SiteConfig.get( db, 'site.send_mail.total', 0 )
    if not mail_total:
        SiteConfig.set(db, 'site.send_mail.total', 0)

    mail_total = db.query(SiteConfig).filter_by(
        key = 'site.send_mail.total').first()

    fm = FileSysMail.get_instance()

    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_html = render_template('custom/mail_template.html', **d)

        if body_html:

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

            mail_total.value = int(mail_total.value) + 1
            fm.send( e, '%s-mail' % mail_total.value )

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

    job.set_ended()
    db.commit()
    dbsession.remove()
Example #29
0
 def init_runtime_data(self):
     db = self.dbsession()
     domain = SiteConfig.get(db, 'domain', '')
     if domain:
         settings.runtime_data['domain'] = json.loads(domain)