电子邮件中的修剪附件

问题描述:

我通过python函数发送电子邮件附件。除了事情之外,一切都还好,我的附属物被修剪。修剪了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()) 

我发现为什么附上了修剪。我忘记关闭文件处理程序,然后再执行我的发送邮件功能。