示例#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()
示例#2
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()
示例#3
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()
示例#4
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()