以下代码片段运行良好,但是在电子邮件中生成的附件文件名称为空(在Gmail中文件名显示为“noname”)。我做错了什么?
file_name = RecordingUrl.split("/")[-1]
file_name=file_name+ ".wav"
urlretrieve(RecordingUrl, file_name)
# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = 'New feedback from %s (%a:%a)' % (
From, int(RecordingDuration) / 60, int(RecordingDuration) % 60)
msg['From'] = "noreply@example.info"
msg['To'] = 'user@gmail.com'
msg.preamble = msg['Subject']
file = open(file_name, 'rb')
audio = MIMEAudio(file.read())
file.close()
msg.attach(audio)
# Send the email via our own SMTP server.
s = smtplib.SMTP()
s.connect()
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
add_header
: http://docs.python.org/library/email-examples.html#id2 - David Webb