Beispiel #1
0
def send_email_to_group(groups, subject, body):
    """
    发送Email给指定的接收group.
    :param groups: group的定义参见settings. group可以是一个字符串, 也可以是一个字符串列表
    :param subject:
    :param body:
    :return:
    """
    if isinstance(groups, list):
        pass
    elif isinstance(groups, basestring):
        groups = [groups]
    else:
        logger.error('Invalid groups: %s' % groups)

    email_receivers = getattr(settings, 'EMAIL_RECEIVERS', {})
    for g in groups:
        # 接收者列表
        targets = email_receivers.get(g, [])
        if targets:
            # 发送邮件
            send_email.apply(kwargs={
                'targets': targets,
                'subject': subject,
                'body': body
            })
        else:
            logger.warning('The email receiver group %s is empty!' % g)
Beispiel #2
0
def send_sms(self, targets, message):
    """
    发送短信
    :param targets: 目标手机号. 可以是表示手机号的字符串, 或多个这样的手机号, 表示同时发送给多个手机
    :param message: 需要发送的内容.
    :return: 如果发送成功, 返回短信网关的任务ID. 否则返回None.
    """
    logger.info('target: %s, message: %s' % (targets, message))
    logger.error('target: %s, message: %s' % (targets, message))