gpt4 book ai didi

Python Unresolved 引用导入 MIMEMultipart

转载 作者:行者123 更新时间:2023-11-28 20:39:56 24 4
gpt4 key购买 nike

我正在 Pycharm 中编写一些代码,以通过带有附件的电子邮件发送我的 Selenium 测试结果报告。

在我的导入语句中我收到错误:

unresolved reference MIMEMultipart
unresolved reference MIMEText
unresolved reference MIMEBase

我的导入语句是这样写的:

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase

我需要安装任何软件包吗?

我的完整代码片段是:

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase

class Email(BasePage):


def send_email(self):
import smtplib


from email import encoders

fromaddr = "YOUR EMAIL"
toaddr = "EMAIL ADDRESS YOU SEND TO"

msg = MIMEMultipart()

msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE EMAIL"

body = "TEXT YOU WANT TO SEND"

msg.attach(MIMEText(body, 'plain'))

filename = "NAME OF THE FILE WITH ITS EXTENSION"
attachment = open("PATH OF THE FILE", "rb")

part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)

msg.attach(part)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "YOUR PASSWORD")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()

最佳答案

使用 python 3.6:

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

关于Python Unresolved 引用导入 MIMEMultipart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36967766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com