-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_function2.py
More file actions
116 lines (109 loc) · 3.58 KB
/
email_function2.py
File metadata and controls
116 lines (109 loc) · 3.58 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import pandas as pd
from tkinter import filedialog
global fob
# def email_send_funct_next(to_, sub_, msg_, from_, pass_):
# s = smtplib.SMTP("smtp.gmail.com", 587)
# s.starttls()
# s.login(from_, pass_)
# msg = MIMEMultipart()
# msg['From'] = from_
# msg['To'] = to_
# msg['Subject'] = sub_
# body = msg_
# msg.attach(MIMEText(body, 'plain'))
# filename = "test1.xlsx"
# attachment = open(filename, "rb")
# data = pd.read_excel(attachment.name)
# all_emails = data['Email']
# email2 = all_emails
# # p = MIMEBase('application', 'octet-stream')
# # # p.set_payload(attachment.read())
# # # encoders.encode_base64(p)
# # p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
# # msg.attach(p)
# text = msg.as_string()
# s.sendmail(from_, email2, text)
# x = s.ehlo()
# if x[0] == 250:
# return "s"
# else:
# return "f"
# s.close()
def attach_single(to_, sub_, msg_, from_, pass_):
s = smtplib.SMTP("smtp.gmail.com", 587)
s.starttls()
s.login(from_, pass_)
msg = MIMEMultipart()
msg['From'] = from_
msg['To'] = to_
msg['Subject'] = sub_
body = msg_
msg.attach(MIMEText(body, 'plain'))
f_types = [('All Files', '*.*'),
('Python Files', '*.py'),
('Text Document', '*.txt'),
('Excel files', "*.xlsx")]
file = filedialog.askopenfilename(initialdir='E:',
filetypes=f_types)
if file:
fob = open(file, 'rb')
filename = file
p = MIMEBase('application', 'octet-stream')
p.set_payload((fob).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
text = msg.as_string()
s.sendmail(from_, to_, text)
x = s.ehlo()
if x[0] == 250:
return "s"
else:
return "f"
s.close()
def attach_mul(to_, sub_, msg_, from_, pass_):
s = smtplib.SMTP("smtp.gmail.com", 587)
s.starttls()
s.login(from_, pass_)
msg = MIMEMultipart()
msg['From'] = from_
msg['To'] = to_
msg['Subject'] = sub_
body = msg_
msg.attach(MIMEText(body, 'plain'))
f_types2 =[('All Files', '*.*'),
('Excel Files', '*.xlsx')]
file2 = filedialog.askopenfilename(initialdir='E:', title = 'Please Select the Excel Sheet',
filetypes=f_types2)
filename = file2
attachment = open(filename, "rb")
data = pd.read_excel(attachment.name)
all_emails = data['Email']
email2 = all_emails
f_types = [('All Files', '*.*'),
('Python Files', '*.py'),
('Text Document', '*.txt'),
('Excel files', "*.xlsx")]
file = filedialog.askopenfilename(initialdir='E:', title = 'Please Select the attachment',
filetypes=f_types)
if file:
fob = open(file, 'rb')
filename2 = file
p = MIMEBase('application', 'octet-stream')
p.set_payload((fob).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename2)
msg.attach(p)
text = msg.as_string()
s.sendmail(from_, email2, text)
x = s.ehlo()
if x[0] == 250:
return "s"
else:
return "f"
s.close()