Пример #1
0
def SEND_MAIL(k,sender,password):
    '''
    send mail
    '''
    subject = 'python email test'
    smtpserver = 'smtp.163.com'
    msg = MIMEMultipart('alternative')
    msg['Subject'] = u"共享文件服务器" 
    company_name = k[0].split('_')[0]
    user = k[1]['username']
    Pass = k[1]['passwd']
    if 'vpn' in k[1]:
        html = u"""\
            您好,给你新开的VPN账号和密码为:$user,$vpn_pass。VPN连接方法见附件,不会连接VPN的联系网管设定使用。
            您需要的文件系统账号跟密码为:$user,$Pass。
            文件系统使用方法:使用前必须连接上VPN,打开计算机在地址栏输入\\192.168.1.240,然后进入$company_name目录。
            以后文件系统的权限修改请联系[email protected]!
            xxx-xxx
        """ 
        html = Template(html)
        if 'vpn' in k[1]:
            html = html.substitute(user=k[1]['username'],Pass=k[1]['passwd'],vpn_pass=k[1]['vpn']['vpn_pass'],company_name=k[0].split('_')[0])
        try:

            attach_file = gain_profilePath('/mail attachment')+userconf()['file name']
            att = MIMEText(open(attach_file, 'rb').read(), 'base64', 'utf-8')
            att["Content-Type"] = 'application/octet-stream'
            att["Content-Disposition"] = 'attachment; filename="file"'
            msg.attach(att)
            part2 = MIMEText(html, 'html','utf-8') 
            msg.attach(part2)
        except Exception,e:
            error_info = e
            log_record(error_info)
            exit(0)
Пример #2
0
#记录所有name.yaml里的配置
def save_yaml():
    saveall = gain_profilePath('/save_all_operation/')
    if os.path.exists(saveall) is False:
        os.mkdir(saveall)
    saveallyaml = saveall+'/all_name.yaml'
    f1 = open(gain_profilePath('/etc/name.yaml'),'r')
    f2 = open(saveallyaml ,'a')
    for i in f1.readlines():
        f2.write(i)
    f2.close()
    f1.close()

if __name__ == '__main__':
    address = userconf()['mail']
    p=re.compile('[^\._-][\w\.-]+@(?:[A-Za-z0-9]+\.)+[A-Za-z]+$')
    match = p.match(address)  
    if match:
        try:
            pas = userconf()['password']
        except Exception,e:
            error_info = e
            log_record(error_info)
            exit(0)
        try:
            pass_count()
        except Exception,e:
            error_info = e
            log_record(error_info)
            exit(0)