-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackup.py
More file actions
53 lines (38 loc) · 1.13 KB
/
backup.py
File metadata and controls
53 lines (38 loc) · 1.13 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
# import necessary packages
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import smtplib
# create message object instance
msg = MIMEMultipart()
message = "Thank you"
# setup the parameters of the message
# Enter Your Password
password = ""
# Enter Your Email ID
msg['From'] = ""
# Enter Receiver's Email ID
msg['To'] = ""
# Subject Of Email
msg['Subject'] = "Backup"
#File attach
filename = 'blog.sql'
attachemnt = open(filename,'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachemnt).read())
#encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachemnt; filename"+filename)
msg.attach(part)
# add in the message body
msg.attach(MIMEText(message, 'plain'))
#create server
server = smtplib.SMTP('smtp.gmail.com: 587')
server.starttls()
# Login Credentials for sending the mail
server.login(msg['From'], password)
# send the message via the server.
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
#print "successfully sent email to %s:" %(msg['To'])