-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailer.py
More file actions
59 lines (52 loc) · 1.86 KB
/
Copy pathmailer.py
File metadata and controls
59 lines (52 loc) · 1.86 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
51
52
53
54
55
56
57
58
59
from smtplib import SMTP
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import getpass
class sendClass():
username = None
host = "smtp.gmail.com"
port = 587
from_email = username
to_email = None
plain_txt = None
e_conn = None
def set_Conn():
try:
print("Connecting!")
sendClass.e_conn = SMTP(sendClass.host, sendClass.port)
print(sendClass.e_conn.ehlo())
print(sendClass.e_conn.starttls())
# password = input("Enter the password: ")
password = getpass.getpass(prompt="Enter your password: ")
print(sendClass.e_conn.login(sendClass.username, password))
print("Connected to SMTP server!")
# plain_txt = "This is a test message in plain!!"
except:
print("Error in login!")
finally:
print("Logged in!")
def send_email():
try:
# print(sendClass.e_conn)
print("Sending mail to", sendClass.to_email)
the_msg = MIMEMultipart("alternative")
the_msg['Subject'] = "Hello There!"
# print(sendClass.username)
the_msg['From'] = sendClass.username
part1 = MIMEText(sendClass.plain_txt, "plain")
# part2 = MIMEText(html_txt, "html")
the_msg.attach(part1)
# the_msg.attach(part2)
sendClass.e_conn.sendmail(sendClass.username, sendClass.to_email,
the_msg.as_string())
print("Mail send!")
except Exception as error:
print("Error occurred!", error)
finally:
print("Done")
def quit_email():
try:
print(sendClass.e_conn.quit())
print("Connection closed successfully!")
except:
print("Error in quit!")