使用 python 以 HTML 格式发送每小时报告。需要在文本上启用鼠标,换句话说,当用户将鼠标悬停在报告标题上时,会显示特定文本。
尝试了以下方法,但在 outlook 中阅读电子邮件时确实有效:
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def send_html_email(msg_to_list, msg_from, msg_subject, msg_body, smtp_server):
''' set the subject, To, From and body of the email and send it '''
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('multipart')
msg['Subject'] = msg_subject
msg['From'] = msg_from
msg['To'] = ', '.join(msg_to_list)
# Record the MIME type of the HTML body - text/html.
part = MIMEText(msg_body, 'html')
# Attach parts into message container.
msg.attach(part)
# Send the message via local SMTP server.
s = smtplib.SMTP(smtp_server)
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(msg['From'], msg_to_list, msg.as_string())
s.quit()
title = 'display this when user moves mouse over this header'
html_msg_body = '''<html><body><div align = "center">'''
html_msg_body += '''<br><br><h3 bgcolor="#00BFFF" title=%s>Stats</h3>'''%(title)
html_msg_body += '<br></body>'
html_msg_body += '<br></html>'
msg_body = html_msg_body
msg_to_list = ['me@test.com']
msg_from = 'me@test.com'
msg_subject = "Stats"
smtp_server = 'localhost'
send_html_email(msg_to_list, msg_from, msg_subject, msg_body, smtp_server)
关于需要做什么才能使 outlook 在文本上显示鼠标的任何帮助?
最佳答案
关于python - html 电子邮件 鼠标悬停在文本上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25100676/