Skip to content

Commit 8d148d2

Browse files
Day 11
1 parent 59dfde8 commit 8d148d2

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Day 11/hungrypy/custom.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import smtplib
2+
3+
host = "smtp.gmail.com"
4+
port = 587
5+
username = "[email protected]"
6+
password = "iamhungry2016"
7+
from_email = username
8+
to_list = ["[email protected]"]
9+
10+
email_conn = smtplib.SMTP(host, port)
11+
email_conn.ehlo()
12+
email_conn.starttls()
13+
email_conn.login(username, password)
14+
email_conn.sendmail(from_email, to_list, "Hello there this is an email message")
15+
email_conn.quit()
16+
17+
18+
from smtplib import SMTP
19+
20+
21+
ABC = SMTP(host, port)
22+
ABC.ehlo()
23+
ABC.starttls()
24+
ABC.login(username, password)
25+
ABC.sendmail(from_email, to_list, "Hello there this is an email message")
26+
ABC.quit()
27+
28+
29+
from smtplib import SMTP, SMTPAuthenticationError, SMTPException
30+
31+
32+
pass_wrong = SMTP(host, port)
33+
pass_wrong.ehlo()
34+
pass_wrong.starttls()
35+
try:
36+
pass_wrong.login(username, "wrong_password")
37+
pass_wrong.sendmail(from_email, to_list, "Hello there this is an email message")
38+
except SMTPAuthenticationError:
39+
print("Could not login")
40+
except:
41+
print("an error occured")
42+
43+
pass_wrong.quit()
44+
45+
46+

Day 11/hungrypy/html_format_email.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import smtplib
2+
3+
host = "smtp.gmail.com"
4+
port = 587
5+
username = "[email protected]"
6+
password = "iamhungry2016"
7+
from_email = username
8+
to_list = ["[email protected]"]
9+
10+
email_conn = smtplib.SMTP(host, port)
11+
email_conn.ehlo()
12+
email_conn.starttls()
13+
email_conn.login(username, password)
14+
email_conn.sendmail(from_email, to_list, "<b>Hello</b><br/> there this is an email message")
15+
email_conn.quit()

0 commit comments

Comments
 (0)