Python email MIME attachment filename
问题 I'm having trouble attaching a CSV file to an email. I can send the email fine using smtplib, and I can attach my CSV file to the email. But I cannot set the name of the attached file, and so I cannot set it to be .csv . Also I can't figure out how to add a text message to the body of the email. This code results in an attachment called AfileName.dat , not the desired testname.csv , or better still attach.csv #!/usr/bin/env python import smtplib from email.mime.multipart import MIMEMultipart