- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathemail_send.py
More file actions
Latest commit
53 lines (44 loc) · 1.39 KB
/
Copy pathemail_send.py
File metadata and controls
53 lines (44 loc) · 1.39 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
importsmtplib
fromemail.mime.textimportMIMEText
importopenpyxl
importdatetime
defemail_send(data):
_name=data[0]
_email=data[1]
_subject=data[2]
_content=data[3]
_subject=_subject.replace("{이름}", _name)
_content=_content.replace("{이름}", _name)
try:
s=smtplib.SMTP('smtp.naver.com', 587)
s.starttls()
s.login('naver_id@naver.com', 'app_password')
msg=MIMEText(_content)
msg['Subject'] =_subject
msg['From'] ="naver_id@naver.com"
msg['To'] =_email
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
returnTrue
exceptExceptionase:
print(e)
returnFalse
wb=openpyxl.load_workbook("email_list.xlsx")
ws=wb.active
forrowinws.rows:
rownum=row[0].row
ifrownum==1:
continue
data= (row[0].value, row[1].value, row[2].value, row[3].value)
ifrow[4].value=="성공":
continue
print("email sending --> ", row[0].value, row[1].value)
result=email_send(data)
dt=datetime.datetime.now()
ifresult:
ws['E'+str(rownum)] ="성공"
ws['F'+str(rownum)] =dt.strftime("%Y-%m-%d %H:%M:%S")
else:
ws['E'+str(rownum)] ="실패"
ws['F'+str(rownum)] =dt.strftime("%Y-%m-%d %H:%M:%S")
wb.save("email_list.xlsx")