-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathhtml_email.py
More file actions
36 lines (28 loc) · 826 Bytes
/
html_email.py
File metadata and controls
36 lines (28 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import smtplib
from email.message import EmailMessage
from email.utils import make_msgid
msg = EmailMessage()
asparagus_cid = make_msgid()
msg.add_alternative("""\
<html>
<head></head>
<body>
<p>Hello</p>
<p>Here is an example of sending HTML email using Python. Please click on below link:
<a href="https://roytuts.com/how-to-send-an-html-email-using-python/">
Send an HTML email using Python
</a>
</p>
</body>
</html>
""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
fromEmail = 'gmail@gmail.com'
toEmail = 'gmail@gmail.com'
msg['Subject'] = 'HTML Message'
msg['From'] = fromEmail
msg['To'] = toEmail
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(fromEmail, 'gmail password')
s.send_message(msg)
s.quit()