Ejemplo n.º 1
0
def send_email(recipients, subject, body='', html_body=''):
    """
    Sends an email with defined parameters from the .ini files.

    :param recipients: list of recipients, it this is empty the defined email
        address from field 'email_to' is used instead
    :param subject: subject of the mail
    :param body: body of the mail
    :param html_body: html version of body
    """
    log = get_logger(send_email)
    DBS = get_session()

    email_config = config
    subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
    if not recipients:
        # if recipients are not defined we send to email_config + all admins
        admins = [
            u.email for u in User.query().filter(User.admin == True).all()
        ]
        recipients = [email_config.get('email_to')] + admins

    mail_from = email_config.get('app_email_from', 'RhodeCode')
    user = email_config.get('smtp_username')
    passwd = email_config.get('smtp_password')
    mail_server = email_config.get('smtp_server')
    mail_port = email_config.get('smtp_port')
    tls = str2bool(email_config.get('smtp_use_tls'))
    ssl = str2bool(email_config.get('smtp_use_ssl'))
    debug = str2bool(email_config.get('debug'))
    smtp_auth = email_config.get('smtp_auth')

    if not mail_server:
        log.error("SMTP mail server not configured - cannot send mail")
        return False

    try:
        m = SmtpMailer(mail_from,
                       user,
                       passwd,
                       mail_server,
                       smtp_auth,
                       mail_port,
                       ssl,
                       tls,
                       debug=debug)
        m.send(recipients, subject, body, html_body)
    except:
        log.error('Mail sending failed')
        log.error(traceback.format_exc())
        return False
    return True
Ejemplo n.º 2
0
def send_email(recipients, subject, body):
    """
    Sends an email with defined parameters from the .ini files.

    :param recipients: list of recipients, it this is empty the defined email
        address from field 'email_to' is used instead
    :param subject: subject of the mail
    :param body: body of the mail
    """
    try:
        log = send_email.get_logger()
    except:
        log = logging.getLogger(__name__)
    
    sa = get_session()
    email_config = config

    if not recipients:
        # if recipients are not defined we send to email_config + all admins
        admins = [
            u.email for u in sa.query(User).filter(User.admin==True).all()
        ]
        recipients = [email_config.get('email_to')] + admins

    mail_from = email_config.get('app_email_from')
    user = email_config.get('smtp_username')
    passwd = email_config.get('smtp_password')
    mail_server = email_config.get('smtp_server')
    mail_port = email_config.get('smtp_port')
    tls = str2bool(email_config.get('smtp_use_tls'))
    ssl = str2bool(email_config.get('smtp_use_ssl'))
    debug = str2bool(config.get('debug'))
    smtp_auth = email_config.get('smtp_auth')

    try:
        m = SmtpMailer(mail_from, user, passwd, mail_server,smtp_auth,
                       mail_port, ssl, tls, debug=debug)
        m.send(recipients, subject, body)
    except:
        log.error('Mail sending failed')
        log.error(traceback.format_exc())
        return False
    return True
Ejemplo n.º 3
0
def send_email(recipients, subject, body="", html_body=""):
    """
    Sends an email with defined parameters from the .ini files.

    :param recipients: list of recipients, it this is empty the defined email
        address from field 'email_to' is used instead
    :param subject: subject of the mail
    :param body: body of the mail
    :param html_body: html version of body
    """
    log = get_logger(send_email)
    DBS = get_session()

    email_config = config
    subject = "%s %s" % (email_config.get("email_prefix", ""), subject)
    if not recipients:
        # if recipients are not defined we send to email_config + all admins
        admins = [u.email for u in User.query().filter(User.admin == True).all()]
        recipients = [email_config.get("email_to")] + admins

    mail_from = email_config.get("app_email_from", "RhodeCode")
    user = email_config.get("smtp_username")
    passwd = email_config.get("smtp_password")
    mail_server = email_config.get("smtp_server")
    mail_port = email_config.get("smtp_port")
    tls = str2bool(email_config.get("smtp_use_tls"))
    ssl = str2bool(email_config.get("smtp_use_ssl"))
    debug = str2bool(email_config.get("debug"))
    smtp_auth = email_config.get("smtp_auth")

    if not mail_server:
        log.error("SMTP mail server not configured - cannot send mail")
        return False

    try:
        m = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth, mail_port, ssl, tls, debug=debug)
        m.send(recipients, subject, body, html_body)
    except:
        log.error("Mail sending failed")
        log.error(traceback.format_exc())
        return False
    return True
Ejemplo n.º 4
0
def send_email(recipients, subject, body):
    """
    Sends an email with defined parameters from the .ini files.

    :param recipients: list of recipients, it this is empty the defined email
        address from field 'email_to' is used instead
    :param subject: subject of the mail
    :param body: body of the mail
    """
    try:
        log = send_email.get_logger()
    except:
        log = logging.getLogger(__name__)

    email_config = config

    if not recipients:
        recipients = [email_config.get("email_to")]

    mail_from = email_config.get("app_email_from")
    user = email_config.get("smtp_username")
    passwd = email_config.get("smtp_password")
    mail_server = email_config.get("smtp_server")
    mail_port = email_config.get("smtp_port")
    tls = str2bool(email_config.get("smtp_use_tls"))
    ssl = str2bool(email_config.get("smtp_use_ssl"))
    debug = str2bool(config.get("debug"))

    try:
        m = SmtpMailer(mail_from, user, passwd, mail_server, mail_port, ssl, tls, debug=debug)
        m.send(recipients, subject, body)
    except:
        log.error("Mail sending failed")
        log.error(traceback.format_exc())
        return False
    return True
Ejemplo n.º 5
0
from rhodecode.model import init_model
from rhodecode.model import meta
from rhodecode.model.db import RhodeCodeUi, Statistics, Repository

from vcs.backends import get_repo

from sqlalchemy import engine_from_config

add_cache(config)



__all__ = ['whoosh_index', 'get_commits_stats',
           'reset_user_password', 'send_email']

CELERY_ON = str2bool(config['app_conf'].get('use_celery'))


def get_session():
    if CELERY_ON:
        engine = engine_from_config(config, 'sqlalchemy.db1.')
        init_model(engine)
    sa = meta.Session()
    return sa


def get_repos_path():
    sa = get_session()
    q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
    return q.ui_value
Ejemplo n.º 6
0
from vcs.backends import get_repo

from sqlalchemy import engine_from_config

add_cache(config)

try:
    import json
except ImportError:
    # python 2.5 compatibility
    import simplejson as json

__all__ = ["whoosh_index", "get_commits_stats", "reset_user_password", "send_email"]

CELERY_ON = str2bool(config["app_conf"].get("use_celery"))


def get_session():
    if CELERY_ON:
        engine = engine_from_config(config, "sqlalchemy.db1.")
        init_model(engine)
    sa = meta.Session()
    return sa


def get_repos_path():
    sa = get_session()
    q = sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == "/").one()
    return q.ui_value