Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
增加了对邮件附件是否存在的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
BlBana committed Mar 26, 2018
1 parent 12b134b commit 41add93
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cobra/send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ def send_mail(target, filename, receiver):

msg.attach(MIMEText('扫描项目:{t}\n报告见附件'.format(t=target), 'plain', 'utf-8'))

with open(filename, 'rb') as f:
attachment = MIMEApplication(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=os.path.split(filename)[1])
msg.attach(attachment)
try:
with open(filename, 'rb') as f:
attachment = MIMEApplication(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=os.path.split(filename)[1])
msg.attach(attachment)
except IOError:
logger.warning('[EMAIL] No such file {}, please check input parameter'.format(filename))
return False

try:
server.login(user=username, password=password)
Expand Down

0 comments on commit 41add93

Please sign in to comment.