小编zeu*_*lla的帖子

当我在电子邮件收件箱中收到从 Python 发送到 gmail 帐户的“test.txt”文件时,是什么原因导致该文件显示为“无标题”?

我通过 python 程序发送一个名为test.txt附件的文件。它成功发送,但当我在 Gmail 收件箱中收到它时,附件显示Untitled的是text.txt. 我的电子邮件代码块如下,看起来是正确的。有什么建议么?

# Setup the email
mail_content = '''Hello,
The attached document contains the results of the file scan.
Please contact the IT Help Desk if you have any questions.
Thank You!!!
'''
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'A test mail sent by Python. It has an attachment.'
message.attach(MIMEText(mail_content, 'plain'))
attach_file_name = 'david.txt'
# attach_file_name = file_name
attach_file = open(attach_file_name, 'rb')  # Open the …
Run Code Online (Sandbox Code Playgroud)

python mime email-attachments mimemultipart

1
推荐指数
1
解决办法
242
查看次数

标签 统计

email-attachments ×1

mime ×1

mimemultipart ×1

python ×1