zoukankan      html  css  js  c++  java
  • python 发送 html email

     1 import smtplib
     2 
     3 from email.mime.multipart import MIMEMultipart
     4 from email.mime.text import MIMEText
     5 
     6 # me == my email address
     7 # you == recipient's email address
     8 me = "my@email.com"
     9 you = "your@email.com"
    10 
    11 # Create message container - the correct MIME type is multipart/alternative.
    12 msg = MIMEMultipart('alternative')
    13 msg['Subject'] = "Link"
    14 msg['From'] = me
    15 msg['To'] = you
    16 
    17 # Create the body of the message (a plain-text and an HTML version).
    18 text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
    19 html = """\
    20 <html>
    21   <head></head>
    22   <body>
    23     <p>Hi!<br>
    24        How are you?<br>
    25        Here is the <a href="http://www.python.org">link</a> you wanted.
    26     </p>
    27   </body>
    28 </html>
    29 """
    30 
    31 # Record the MIME types of both parts - text/plain and text/html.
    32 part1 = MIMEText(text, 'plain')
    33 part2 = MIMEText(html, 'html')
    34 
    35 # Attach parts into message container.
    36 # According to RFC 2046, the last part of a multipart message, in this case
    37 # the HTML message, is best and preferred.
    38 msg.attach(part1)
    39 msg.attach(part2)
    40 
    41 # Send the message via local SMTP server.
    42 s = smtplib.SMTP('localhost')
    43 # sendmail function takes 3 arguments: sender's address, recipient's address
    44 # and message to send - here it is sent as one string.
    45 s.sendmail(me, you, msg.as_string())
    46 s.quit()
  • 相关阅读:
    路由器DHCP 动态主机配置
    nat转换
    静态路由的实验
    不同vlan之间的相互访问
    IP的包头格式什么?请分析每个字段的含义
    IP地址的分类
    关于对JSON.parse()与JSON.stringify()的理解
    Ajax工作原理
    关于css伪类
    开发 | 如何在微信小程序的页面间传递数据?
  • 原文地址:https://www.cnblogs.com/harveyaot/p/3022581.html
Copyright © 2011-2022 走看看