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