2017-05-21 2 views
0

파이썬 기능을 통해 전자 메일 첨부 파일을 보냅니다. 물건을 제외하고는 모두 괜찮아요, 제 부착물이 다듬어 져 있습니다. 약 200 개의 문자열이 다듬어졌고 어디에서 느슨한 지 이해할 수 없습니다. 디버거에서 내 기능을 확인한 결과 encoders.encode_base64(part) 전에 part.set_payload은 HDD의 파일 크기와 크기가 같지만 결과적으로 잘린 첨부 파일을 받았습니다. 아래이메일에 트림 첨부

메일 보내기 기능 : 손질 된 첨부 할 이유를 찾을 수

def mail_sender(recipients, sender, z_name, z_count=0): 
    for recipient in recipients: 
     msg = MIMEMultipart() 
     sender = '%s' % sender 
     subject = "report on %s" % (time.strftime("%d/%m/%Y")) 
     body = "Good morning, enjoy todays report.\n\nTotal: %d" % z_count 

     msg['From'] = sender 
     msg['To'] = recipient 
     msg['Date'] = formatdate(localtime=True) 
     msg['Subject'] = subject 
     msg.attach(MIMEText(body, 'plain')) 

     part = MIMEBase('application', "base64") 
     part.set_payload(open("result.txt", "rb").read()) 
     encoders.encode_base64(part) 
     part.add_header('Content-Disposition', 'attachment; filename="result.txt"') 
     msg.attach(part) 

     s = smtplib.SMTP('localhost') 
     s.sendmail(sender, recipient, msg.as_string()) 

답변

0

. 내 메일 보내기 기능을 실행하기 전에 파일 처리기를 닫는 것을 잊지 마십시오.

관련 문제