Skip to content

Commit 6256e91

Browse files
committed
add email module
1 parent 4292fea commit 6256e91

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
</head>
5+
<body>
6+
Hello $name.. what a beautiful day :)
7+
</body>
8+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import smtplib
2+
from email.message import EmailMessage
3+
from string import Template
4+
from pathlib import Path
5+
import configparser
6+
7+
config = configparser.RawConfigParser()
8+
config.read('mail.properties')
9+
host_address = config.get('EmailSection','host.address')
10+
port_number = config.get('EmailSection','port.number')
11+
username = config.get('EmailSection','email.username')
12+
password = config.get('EmailSection','email.password')
13+
14+
email = EmailMessage()
15+
email['from'] = 'Tester'
16+
email['to'] = '<to email address>'
17+
email['subject'] = 'testing email !'
18+
19+
html_content = Template(Path('email_content.html').read_text())
20+
email.set_content(html_content.substitute({'name':'Tin Tin'}), 'html')
21+
22+
#need to turn on https://myaccount.google.com/lesssecureapps
23+
with smtplib.SMTP(host=host_address, port=port_number) as smtp:
24+
smtp.ehlo()
25+
smtp.starttls()
26+
smtp.login(username, password)
27+
smtp.send_message(email)
28+
print("email has been sent out successfully!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[EmailSection]
2+
host.address=smtp.gmail.com
3+
port.number=587
4+
email.username=username
5+
email.password=password

readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ PDF processing project which merge multiple pdf files, watermark the pdf files,
3838
### Built with
3939
+ [PyPDF2](https://pythonhosted.org/PyPDF2/)
4040

41+
## Email Sender Project
42+
Email Sender project for sending out email automatically, using gmail host.
43+
### Built with
44+
+ [smtplib](https://docs.python.org/3/library/email.examples.html)
45+
+ [pathlib])https://docs.python.org/3/library/pathlib.html
46+
4147
## API HTTP Request
4248
A simple API requsest project to demostrate making requests and processing responses.
4349
### Built with
@@ -102,6 +108,9 @@ Python projects for connecting various databases such as PostgreSQL, SQLite to c
102108
+ [pillow](https://python-pillow.org/)
103109
+ PDF Processing Project
104110
+ [PyPDF2](https://pythonhosted.org/PyPDF2/)
111+
+ Email Project
112+
+ [smtplib](https://docs.python.org/3/library/email.examples.html)
113+
+ [pathlib])https://docs.python.org/3/library/pathlib.html
105114
+ 17.Machine Learning & Data Science Projects - FIFA players, Iris Flower, Image Prediction
106115
+ [NumPy](https://numpy.org/) - package for scientific computing with Python
107116
+ [pandas](https://pandas.pydata.org/) - fast, powerful, flexible and easy to use open source data analysis and manipulation tool

0 commit comments

Comments
 (0)