你好我试着做一个小监控,在监控.py,它应该发送一封具有发送邮件.sende(). 但我想,我有变量的问题。你能给我一些提示吗?我做错了什么? 这就是发送邮件.py你知道吗
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()
错误:
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')
你没有描述出哪里出了问题,所以只是猜测。但是函数
readLastLog
是错误的:None
nachricht.set_payload(None)
的有效负载其他一些即时改进:
readLastLog
是在sende
体中定义的。。。你知道吗当您构建了一个带有
To:
和From:
头的消息时,您可以使用send_message
函数:所以我改变了readLastLog的返回值,做了一个单独的函数, 不管怎样,这还没有解决问题,所以这里的问题可能是我的@网站.de邮件。 与其他电子邮件一起更改为自己的邮件服务器。现在我确实收到电子邮件了。 抱歉耽误了你的时间。你知道吗
相关问题 更多 >
编程相关推荐