| 1 |
|
| 2 |
|
| 3 |
import smtplib |
| 4 |
|
| 5 |
from email.mime.multipart import MIMEMultipart |
| 6 |
from email.mime.text import MIMEText |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
me = "[email protected]" |
| 11 |
you = "[email protected]" |
| 12 |
|
| 13 |
|
| 14 |
msg = MIMEMultipart('alternative') |
| 15 |
msg['Subject'] = "Link" |
| 16 |
msg['From'] = me |
| 17 |
msg['To'] = you |
| 18 |
|
| 19 |
|
| 20 |
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org" |
| 21 |
html = """\ |
| 22 |
<html> |
| 23 |
<head></head> |
| 24 |
<body> |
| 25 |
<p>Hi!<br> |
| 26 |
How are you?<br> |
| 27 |
Here is the <a href="https://www.python.org">link</a> you wanted. |
| 28 |
</p> |
| 29 |
</body> |
| 30 |
</html> |
| 31 |
""" |
| 32 |
|
| 33 |
|
| 34 |
part1 = MIMEText(text, 'plain') |
| 35 |
part2 = MIMEText(html, 'html') |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
msg.attach(part1) |
| 41 |
msg.attach(part2) |
| 42 |
|
| 43 |
|
| 44 |
s = smtplib.SMTP('localhost') |
| 45 |
|
| 46 |
|
| 47 |
s.sendmail(me, you, msg.as_string()) |
| 48 |
s.quit() |