forked from aniket1004/DuplicateFileRemoval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailSender.py
63 lines (41 loc) · 1.24 KB
/
MailSender.py
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
import urllib.request as urllib2;
import smtplib;
import os;
import psutil;
from sys import *;
import time;
from email import encoders;
from email.mime.text import MIMEText;
from email.mime.base import MIMEBase;
from email.mime.multipart import MIMEMultipart;
def is_connected():
try:
urllib2.urlopen("http://216.58.192.142",timeout=1)
return True;
except urllib2.URLError as err:
return False;
def MailSender(mid,filename,body,time):
try:
fromaddr="aniketdhole1004@gmail.com";
toaddr=mid;
msg=MIMEMultipart();
msg['From']=fromaddr;
msg['To']=toaddr;
Subject="""Remove Duplicate file and log of that work generated at :%s"""%(time);
msg['Subject']=Subject;
msg.attach(MIMEText(body,'plain'));
attachment=open(filename,"rb");
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);
s=smtplib.SMTP('smtp.gmail.com',587)
s.starttls();
s.login(fromaddr,"Maharaj7");
text=msg.as_string();
s.sendmail(fromaddr,toaddr,text);
s.quit();
print("Log file sucessfully sent through mail");
except Exception as E:
print ("Unable to send mail. ",E);