HTML 邮件鼠标悬停文本

4 投票
1 回答
1022 浏览
提问于 2025-04-18 15:46

用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显示鼠标悬停的文本呢?

1 个回答

2

很遗憾,悬停效果在Outlook 2007/2010、Gmail、iOS和Android上都不支持。可以支持这些效果的邮件客户端有:Outlook 2000/2003、Hotmail、Apple Mail和Yahoo!邮件。

撰写回答