smtplib发送带有指定图像的邮件
**我想发送带有特定图片的邮件**
在邮件标题旁边有一张小图片。我想把这张图片换成每次发送邮件时与邮件内容相符的图片。
def check(line):
arre = str(line).split(':')
print(arre)
mail_username="username"
mail_password="password"
try:
from_addr = mail_username
to_addrs=('myemail@gmail.com')
HOST = "smtpDomain"
print(HOST)
PORT = 587
smtp = smtplib.SMTP(HOST)
smtp.connect(HOST,PORT)
time.sleep(2)
smtp.ehlo()
smtp.starttls()
try:
smtp.login(mail_username,mail_password)
print ("goodlogin")
smtp.set_debuglevel(1)
msg = MIMEMultipart()
msg['From'] = "emample@example.com"
msg['To'] = to_addrs
msg['Reply-to'] = "emample@example.com"
msg['Subject']='test message'
msg.add_header('Content-Type', 'text/html')
data = line
msg.attach(MIMEText(data, 'html', 'utf-8'))
print(smtp)
smtp.sendmail(from_addr,[msg['To']],msg.as_string())
print ("done")
except Exception as ee:
print( ee)
smtp.quit()
except Exception as ee:
print ("asd")
print (ee)
我需要帮助,想知道怎么发送不同的图片。
0 个回答
暂无回答