-
Notifications
You must be signed in to change notification settings - Fork 1
/
Email_Compose_Fetch_RecieverPub.py
60 lines (50 loc) · 1.73 KB
/
Email_Compose_Fetch_RecieverPub.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
import os,errno
from pathlib import Path
import getpass
from Code.V1 import getdata,get_key,encrypt,decrypt
#----------------------PREREQUISITE--------------------------------
def makedir(directory):
if not os.path.exists(directory):
os.makedirs(directory)
makedir('Reciever')
Rec=Path('Reciever/Reciever.asc')
if not Rec.is_file():
print("import Reciever PGP Key")
#-----------------------ENCRYPTING DATA-----------------------------------
print("Email data:")
lin = []
while True:
line = input()
if line:
lin.append(line)
else:
break
d = '\n'.join(lin)
print("Encrypting using Pubkey of Reciever")
en=encrypt(d,'Reciever/Reciever')
open('Reciever/Endata.asc','wb').write(en)
#------------------------DONE---------------------------
d=open('Reciever/Endata.asc','rb').read()
#--------------------------FIGURE OUT SMTP PART-----------------------------------------
usr=input("From:")
pswd = getpass.getpass('Password:')
to=input("To:")
sub=input("Subject:")
def send_email(user,pasw,recv,sub,body):
import smtplib
_message="""From:%s\nTo:%s\nSubject:%s\n\n%s"""%(user,recv,sub,body)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(user, pasw)
server.sendmail(user,recv,_message)
server.close()
print('successfully sent the mail')
except:
print("Failed to send mail")
send_email(usr,pswd,to,sub,bytes(open('Reciever/Endata.asc','rb').read()))
#---------------------------------DONE---------------------------------
#--------------------------------Figure retriving and decypting---------------------------
d=open('Reciever/Endata.asc','rb').read()
print(str(decrypt(d,'Reciever/Recieverkey')))