有人知道为什么以下内容不起作用吗?我正在尝试发送包含PNG的电子邮件。当我运行代码时,没有错误出现,但它似乎终止得太快了,然后什么也没有发生。格式错误吗?
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
def SendMail(Goat):
img_data = open(Goat, 'rb').read()
msg = MIMEMultipart()
msg['Subject'] = 'Goat'
msg['From'] = 'from'
msg['To'] = 'to'
text = MIMEText("test")
msg.attach(text)
image = MIMEImage(img_data, name=os.path.basename('path'))
msg.attach(image)
smtpObj = smtplib.SMTP('smtp-mail.outlook.com', 587)
smtpObj.ehlo()
smtpObj.starttls()
smtpObj.login('email', 'password')
smtpObj.sendmail('to', 'from', msg.as_string())
smtpObj.quit()