以下代码片段工作正常,除了电子邮件中生成的附件文件名为空白(该文件在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()