-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendEmail.py
More file actions
50 lines (43 loc) · 1.64 KB
/
sendEmail.py
File metadata and controls
50 lines (43 loc) · 1.64 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
''' This programs can send Email to required persons with attachments as well...'''
import smtplib, ssl
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender = "santiwartest2603@gmail.com"
receiver = "tiwari.sandarbh2603@gmail.com"
# password = input("Please enter password of your Email to login and send the email: ")
message = MIMEMultipart("alternative")
message["Subject"] = "This is a MIMEMultipart Alternative Test Email"
message["From"] = sender
message["To"] = receiver
text = """ Hi, How are you? \n Hope you are doing good amid this Covid-19. """
html = """\
<html>
<head>
<style type="text/css">
@import url('https://fonts.googleapis.com/css2?family=Montserrat&family=Oswald&display=swap');
h1,h2,h3,h4,h5,h6 {font-family: 'Oswald', sans-serif;}
p, a, li, ul, ol {font-family: 'Montserrat', sans-serif;}
</style>
</head>
<body>
<h2 style="color : #dc143c;">Hi Sandarbh!</h2><br>
<p>This is a test email from Python Script. Please do not revert back.</p>
</body>
</html>
"""
part1 = MIMEText(text, "plain")
part2 = MIMEText(html, "html")
message.attach(part1)
message.attach(part2)
def sendEmail():
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender, password)
server.sendmail(
sender, receiver, message.as_string()
)
if __name__ == '__main__':
password = input("Please enter password of your Email to login and send the email: ")
sendEmail()