當前位置: 首頁>>代碼示例>>Python>>正文


Python Utils.sendmail方法代碼示例

本文整理匯總了Python中Cerebrum.Utils.sendmail方法的典型用法代碼示例。如果您正苦於以下問題:Python Utils.sendmail方法的具體用法?Python Utils.sendmail怎麽用?Python Utils.sendmail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cerebrum.Utils的用法示例。


在下文中一共展示了Utils.sendmail方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _send_mail

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def _send_mail(mail_to, mail_from, subject, body, logger,
               mail_cc=None, debug_enabled=False):
    if debug_enabled:
        logger.debug("Sending mail to %s. Subject: %s", mail_to, subject)
        # logger.debug("Body: %s" % body)
        return True

    try:
        Utils.sendmail(
            toaddr=mail_to,
            fromaddr=mail_from,
            subject=subject,
            body=body,
            cc=mail_cc,
            debug=debug_enabled)
    except smtplib.SMTPRecipientsRefused as e:
        failed_recipients = e.recipients
        for mail, condition in failed_recipients.iteritems():
            logger.exception("Failed when notifying %s (%s): %s",
                             mail_to, mail, condition)
        return False
    except Exception as e:
        logger.error("Error when notifying %s: %s" % (mail_to, e))
        return False
    return True
開發者ID:,項目名稱:,代碼行數:27,代碼來源:

示例2: email_report

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def email_report(to_address, from_address, report):
    """Send the report by email."""
    import smtplib
    try:
        Utils.sendmail(to_address, from_address, 'ePhorte role report',
                             report, cc=None)
    except smtplib.SMTPRecipientsRefused, e:
        failed_recipients = e.recipients
        logger.info("Failed to notify <%d> users", len(failed_recipients))
        for email, condition in failed_recipients.iteritems():
            logger.info("Failed to notify: %s", condition)
開發者ID:,項目名稱:,代碼行數:13,代碼來源:

示例3: main

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hsdf:',
                                   ['help', 'summary', 'detail',
                                    'min=', 'max=',
                                    'mail-to=', 'mail-from=',
                                    'file='])
    except getopt.GetoptError:
        usage("Argument error!", 1)

    detail = False
    minimum = 1  
    maxmum = None
    report_type = 'screen'
    outputstream = sys.stdout
    mail_to = None
    mail_from = None
    persons = 'person_id'
    
    for opt, val in opts:
        if opt in ('-h', '--help'):
            usage()
        elif opt in ('-s', '--summary'):
            pass
        elif opt in ('-d', '--detail'):
            detail = True
        elif opt in ('--min'):
            minimum = int(val)
            if minimum < 0:
                usage("Error: the value of parameter --min should be at least 1", 2)
        elif opt in ('--max'):
            maxmum = int(val)
            if maxmum < 0:
                usage("Error: the value of parameter --max should be at least 1", 3)
        elif opt in ('-f', '--file'):
            report_type = 'file'
            outputstream = open(val, 'w')
            outputstream.write("==== Results of checking active accounts in Cerebrum ====\n")
            outputstream.write("person_id\tNr_accounts\taccount_names\n")
        elif opt in ('--mail-to'):
            report_type = 'mail'
            mail_to = val
        elif opt in ('--mail-from'):
            mail_from = val
        else:
            usage("Error: Unknown parameter '%s'" % opt, 4)

    persons += checkACaccount(minimum,maxmum,detail,report_type,outputstream)
          
    if mail_to:
        count = persons.count("\n")
        subject = "Warning: these following %s persons have more than %s active accounts." % (count,minimum)
        Utils.sendmail(mail_to, mail_from, subject, persons)
開發者ID:,項目名稱:,代碼行數:55,代碼來源:

示例4: generate_mail_notification

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def generate_mail_notification(quar_info, event_info, debug=False):
    if event_info['change_type'] == 'quarantine:mod':
        event_type = 'altered'
    elif event_info['change_type'] == 'quarantine:add':
        event_type = 'added'
    elif event_info['change_type'] == 'quarantine:del':
        event_type = 'deleted'
    else:
        raise Errors.CerebrumError('Unknown quarantine action: %s'
                                   % event_info['change_type'])
    subject = 'Quarantine %s %s on account %s' % \
              (quar_info['name'], event_type, event_info['subject'])
    body = ('Quarantine %s %s on %s.\n\n'
            'When: %s\n'
            'By: %s\n'
            'Change-ID: %s') % (quar_info['name'],
                                event_type,
                                event_info['subject'],
                                event_info['time_stamp'],
                                event_info['change_by'],
                                event_info['change_id'])
    return Utils.sendmail(quar_info['mail_to'],
                          quar_info['mail_from'],
                          subject,
                          body,
                          debug=debug)
開發者ID:,項目名稱:,代碼行數:28,代碼來源:

示例5: send_mail

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def send_mail(mail_to, mail_from, subject, body, mail_cc=None):
    """Function for sending mail to users.

    Will respect dryrun, as that is given and handled by Utils.sendmail, which
    is then not sending the e-mail.

    @type mail_to: string
    @param mail_to: The recipient of the Email.

    @type mail_from: string
    @param mail_from: The senders address.

    @type subject: string
    @param subject: The messages subject.

    @type body: string
    @param body: The message body.

    @type mail_cc: string
    @param mail_cc: An optional address that the mail will be CCed to.

    @rtype: bool
    @return: A boolean that tells if the email was sent sucessfully or not.
    """
    try:
        ret = Utils.sendmail(mail_to, mail_from, subject, body,
                             cc=mail_cc, debug=dryrun)
        if debug_verbose:
            print "---- Mail: ---- \n" + ret
    except smtplib.SMTPRecipientsRefused, e:
        failed_recipients = e.recipients
        logger.info("Failed to notify <%d> users", len(failed_recipients))
        for _, condition in failed_recipients.iteritems():
            logger.info("Failed to notify: %s", condition)
開發者ID:,項目名稱:,代碼行數:36,代碼來源:

示例6: main

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "hds:c:t:f:", ["help", "dryrun", "start-date=", "change-program=", "mail-to=", "mail-from="]
        )
    except getopt.GetoptError:
        usage(1)

    change_program = None
    mail_to = None
    mail_from = None
    dryrun = False
    sdate = DateTime.now() - 1
    for opt, val in opts:
        if opt in ("-h", "--help"):
            usage()
        if opt in ("-d", "--dryrun"):
            dryrun = True
        elif opt in ("-s", "--start-date"):
            try:
                sdate = DateTime.ISO.ParseDate(val)
            except ValueError:
                logger.error("Incorrect date format")
                usage(exitcode=2)
        elif opt in ("-c", "--change-program"):
            change_program = val
        elif opt in ("-t", "--mail-to"):
            mail_to = val
        elif opt in ("-f", "--mail-from"):
            mail_from = val

    new_persons = get_new_persons(sdate, change_program=change_program)
    if new_persons:
        msg = report_new_persons(new_persons)
        if change_program:
            subject = "New persons from %s since %s" % (change_program, sdate.date)
        else:
            subject = "New persons since %s" % sdate.date
        if mail_to and not dryrun:
            Utils.sendmail(mail_to, mail_from, subject, msg)
        else:
            print msg
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:44,代碼來源:report_new_persons.py

示例7: print

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
    # Compare mailbox state between Cerebrum and Exchange
    new_state, report = sc.compare_mailbox_state(mb_info, cere_mb_info,
                                                 state, attr_config)

    # Join the report together
    try:
        rep = u'\n'.join(report)
    except UnicodeDecodeError, e:
        print(str(e))
        tmp = []
        for x in report:
            tmp.append(x.decode('UTF-8'))
        rep = u'\n'.join(tmp)

    # Send the report by mail
    if mail and sender:
        Utils.sendmail(mail, sender, 'Exchange mailbox state report',
                       rep.encode('utf-8'))

    # Write the report to file
    if repfile:
        f = open(repfile, 'w')
        f.write(rep.encode('utf-8'))
        f.close()

    # TODO: Exceptions?
    # Overwrite the old state with the new one.
    f = open(state_file, 'w')
    pickle.dump(new_state, f)
    f.close()
開發者ID:,項目名稱:,代碼行數:32,代碼來源:

示例8: print

# 需要導入模塊: from Cerebrum import Utils [as 別名]
# 或者: from Cerebrum.Utils import sendmail [as 別名]
    ex_group_info = sc.collect_exchange_group_info(group_ou)
    sc.close()

    cere_group_info = sc.collect_cerebrum_group_info(conf["mailbox_spread"], conf["ad_spread"])

    # Compare group state
    new_state, report = sc.compare_group_state(ex_group_info, cere_group_info, state, attr_config)

    try:
        rep = u"\n".join(report)
    except UnicodeDecodeError, e:
        print(str(e))
        tmp = []
        for x in report:
            tmp.append(x.decode("UTF-8"))
        rep = u"\n".join(tmp)
    # Send a report by mail
    if mail and sender:
        Utils.sendmail(mail, sender, "Exchange group state report", rep.encode("utf-8"))

    # Write report to file
    if repfile:
        f = open(repfile, "w")
        f.write(rep.encode("utf-8"))
        f.close()

    # TODO: Exceptions?
    f = open(state_file, "w")
    pickle.dump(new_state, f)
    f.close()
開發者ID:unioslo,項目名稱:cerebrum,代碼行數:32,代碼來源:exchange_group_state_verification.py


注:本文中的Cerebrum.Utils.sendmail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。