Gửi html email từ python thông qua smtp server của Google (Gmail)

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


gmail_user = "my_email@gmail.com"
gmail_pwd = "my_password"

receiver = "receiver_email@email.com"

message = MIMEMultipart('alternative')
message['Subject'] = "this is the email's subject"
message['From'] = gmail_user
message['To'] = receiver

html_content = """\
<html>
<head></head>
  <body>
    <p>Hi!<br>
       How are you?<br>
       Here is the <a href="http://www.python.org">link</a> you wanted.
    </p>
  </body>
</html>
"""

# text_content: alternative version of html_content,
# this will be displayed in receiver's mail client in case it can not render html content
text_content = """Hi!
How are you?
Here is the link you wanted:
http://www.python.org"""

part1 = MIMEText(text_content, 'plain')
part2 = MIMEText(html_content, 'html')
message.attach(part1)
message.attach(part2)

server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server.login(gmail_user, gmail_pwd)

server.sendmail(gmail_user, receiver, message.as_string())
server.close()