Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python发送电子邮件而不暴露密码?_Python_Email - Fatal编程技术网

如何使用Python发送电子邮件而不暴露密码?

如何使用Python发送电子邮件而不暴露密码?,python,email,Python,Email,此代码段有效,但代码中的密码是完全开放的: import smtplib server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo() server.login("usrname", "pw") msg = "\nHello!" # The /n separates the message from the headers server.sendmail("me@gmail.

此代码段有效,但代码中的密码是完全开放的:

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("usrname", "pw")

msg = "\nHello!" # The /n separates the message from the headers
server.sendmail("me@gmail.com", "u@gmail.com", msg)
server.quit()
我想知道如何安全地执行此操作

编辑:

我正在寻找“keystorage”解决方案,就像任何真正的电子邮件客户端使用的解决方案一样,它可以安全地(希望)将您的密码存储在磁盘上。

查看模块。您可以使用getpass提示输入密码,这样密码就不会存储在代码中

用法:

>>> import getpass
>>> password = getpass.getpass()
Password: 
>>> print password
s3cr3t
也许你可以:

使用env变量,例如:
导出PWD=xx
,然后在python中:
导入操作系统;pwd=os.environ.get('pwd')

使用文件记录密码,然后将其放在其他位置。然后
打开(passwdfile)为fi:pwd=fi.read().strip()


如果您的smtp服务器支持,建议您使用ssl。

input()
(或python 2中的
raw\u input()
)?这个问题与python或电子邮件有关吗?您是否在寻找“将pw存储在不同的文件中”、“每次请求pw”、“使用Keystrage解决方案”之类的想法?我正在寻找“Keystrage”解决方案,就像任何真正的电子邮件客户端使用的解决方案一样,它将您的密码安全地(希望)存储在磁盘上,这比我拥有的要好,尽管我希望在pwd上进行某种加密。把它藏起来对我来说很不舒服。