回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>你好我试着做一个小监控,在监控.py,它应该发送一封具有发送邮件.sende(). 但我想,我有变量的问题。你能给我一些提示吗?我做错了什么?
这就是发送邮件.py你知道吗</p>
<pre><code>def sende():
import smtplib
import configparser
from email.message import Message
config = configparser.ConfigParser()
config.read('config.ini')
absender=(config['SMTP']['absender'])
password=(config['SMTP']['password'])
empfaenger=(config['SMTP']['empfaenger'])
smtphost=(config['SMTP']['smtphost'])
port=int(config['SMTP']['port'])
def readLastLog():
log=open('log', 'r')
for line in log:
last= line
print (last)
log.close()
#check for if variables is correct
print("Email Config:")
print(absender, '\n',empfaenger,'\n',smtphost,'\n',port)
server = smtplib.SMTP_SSL(host=smtphost, port=port)
#do I need realy need this?
#server.esmtp_features['auth'] = 'LOGIN PLAIN'
nachricht = Message()
nachricht.set_payload(readLastLog())
nachricht["Subject"] = "Kritische Warnung - Hardlimit erreicht"
nachricht["FROM"] = absender
nachricht["To"] = empfaenger
server.login(absender, password)
server.sendmail(absender, empfaenger, nachricht.as_string())
server.quit()
sende()
</code></pre>
<p>错误:</p>
<pre><code>Traceback (most recent call last):
File "./sendmail.py", line 42, in <module>
sende()
File "./sendmail.py", line 38, in sende
server.login(absender, password)
File "/usr/lib/python3.5/smtplib.py", line 729, in login
raise last_exception
File "/usr/lib/python3.5/smtplib.py", line 720, in login
initial_response_ok=initial_response_ok)
File "/usr/lib/python3.5/smtplib.py", line 641, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Error: authentication failed: authentication failure')
</code></pre>