특정 파일이 생성 될 때 자동으로 이메일을 전송하는 python 스크립트를 작성하려고합니다. 전자 메일을 보내는 코드가 있지만 특정 파일을 찾는 디렉터리를 모니터링하는 방법을 모르겠다 고 생각합니다.은 파일이 생성 될 때 자동으로 이메일을 보냅니다.
하이 레벨의 예는 다음 디렉토리 foo를 이내에서
/ 파일 바즈가 채워지면 your_file.txt가 생성되었을 때 모니터 sendEmail()
특정 파일이 생성 될 때 자동으로 이메일을 전송하는 python 스크립트를 작성하려고합니다. 전자 메일을 보내는 코드가 있지만 특정 파일을 찾는 디렉터리를 모니터링하는 방법을 모르겠다 고 생각합니다.은 파일이 생성 될 때 자동으로 이메일을 보냅니다.
하이 레벨의 예는 다음 디렉토리 foo를 이내에서
/ 파일 바즈가 채워지면 your_file.txt가 생성되었을 때 모니터 sendEmail()
import os.path
if os.path.exists(file_path) and os.path.isfile(fname):
send_email()
import smtplib,time
def search_file():
try:
my_file=open('your_file.txt','r')
content=my_file.read()
my_file.close()
return content
except:
print "Waiting..."
time.sleep(20)
search_log()
mail=smtplib.SMTP('smtp.gmail.com',587)
mail.starttls()
mail.login('user','pwd')
mail.sendmail('originator','receiver',search_log())
mail.close()
또 다른 방법에 대해 = 서버 ESMTP
mail.ehlo()
import os
if 'your_file.txt' in os.listdir(os.getcwd()):
#do something
어떤 운영체제에 있습니까? – Chris
@Chris on windows – StillLearningToCode