域帐号密码过期邮件提醒
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了域帐号密码过期邮件提醒相关的知识,希望对你有一定的参考价值。
思路,通过AD工具取得全部OU下人员工号、邮箱地址,再检测工号多少天没修改密码,超过设定的天数,就执行发送邮件
# -*- coding:utf-8 -*- import smtplib import os import smtplib from email.mime.text import MIMEText from email.utils import formataddr #jj_gonghao=['jjtest001','jjtest002','jjtest003'] dont_check = ['jjtest004','jjtest005'] days = '40' def sendmail(gonghao,days): print('days = ' + days +' ') my_sender='[email protected]' my_pass = '[email protected]' print('get email'+ gonghao) z = os.popen('dsquery user -samid '+ gonghao +' | dsget user -email').read() # print(z) email = z.split(' ') print(email) my_user= email[1].strip() print(my_user) if '@airmate-jiu' not in my_user: print(gonghao + 'dont have email') else: print('gonghao is :'+ my_user) msg=MIMEText('温馨提醒:您的工号'+gonghao+'密码已使用超过'+ days +'天,即将过期,为避免影响您的工作,建议及时修改。修改密码方法:<br/>方法一:按CTRL+ALT+DEL 键后,在弹出界面选择 更改密码 <br/>方法二:通过进入链接 <a href="https://ip_addr/iisadmpwd/">https://ip/iisadmpwd/</a> 进行修改(如提示此网站安全证书有问题,点击继续浏览此网站即可)','html','utf-8') msg['From']=formataddr(["邮件发件名",my_sender]) msg['To']=formataddr([my_user,my_user]) msg['Subject']='温馨提醒:您的工号'+gonghao+'开机密码即将过期,请及时修改' server=smtplib.SMTP("SMTPSERVER_ADDR") server.login(my_sender, my_pass) server.sendmail(my_sender,[my_user,],msg.as_string()) server.quit() print('send mail success... ') #print('===============================now is check password not change =========') info=os.popen("dsquery user ou=XXX,dc=XXX,dc=XXX -stalepwd " + str(days) + " -limit 0 -o upn").read() info=info.split(' ') while '' in info:info.remove('') print(info) for i in info: #print(' i is =================================' + i + ' ') tmp = eval(i) # print(' eval is ================================' + tmp + ' ') CN_NAME = tmp.split('@') gonghao = CN_NAME[0] try: # if gonghao in jj_gonghao: if gonghao not in dont_check: print('========================= ' + 'now sendmail funcntion ...') sendmail(gonghao,days) except: print('error')
以上是关于域帐号密码过期邮件提醒的主要内容,如果未能解决你的问题,请参考以下文章