1import smtplib
2
3from email.mime.multipart import MIMEMultipart
4from email.mime.text import MIMEText
5
6msg = MIMEMultipart('alternative')
7
8msg['Subject'] = "Link"
9msg['From'] = "my@email.com"
10msg['To'] = "your@email.com"
11
12text = "Hello World!"
13
14html = """\
15<html>
16 <head></head>
17 <body>
18 <p style="color: red;">Hello World!</p>
19 </body>
20</html>
21"""
22
23part1 = MIMEText(text, 'plain')
24part2 = MIMEText(html, 'html')
25
26msg.attach(part1) # text must be the first one
27msg.attach(part2) # html must be the last one
28
29s = smtplib.SMTP('localhost')
30s.sendmail(me, you, msg.as_string())
31s.quit()
32