-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendemail.py
More file actions
62 lines (46 loc) · 1.5 KB
/
sendemail.py
File metadata and controls
62 lines (46 loc) · 1.5 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
54
55
56
57
58
59
60
61
62
#add some more lines for push test
import smtplib
from cryptography.fernet import Fernet
#############################################################
# read login and password
file= open("/home/ubuntu/test_key",'rb')
stored_key=file.readline()
file.close()
file= open("/home/ubuntu/test_login",'rb')
stored_login=file.readline()
file.close()
file= open("/home/ubuntu/test_pwd",'rb')
stored_pwd=file.readline()
file.close()
f = Fernet(stored_key)
f.decrypt(stored_login)
f.decrypt(stored_pwd)
# Gmail Sign In
gmail_sender = str(f.decrypt(stored_login))
gmail_passwd = str(f.decrypt(stored_pwd))
#need to strip out the quotes and b at the beginning
gmail_sender = gmail_sender[2:-1]
gmail_passwd = gmail_passwd[2:-1]
############################################################
#print("gmail sender is "+gmail_sender)
#print("gmail password is "+gmail_passwd)
############################################
# compose message
TO = 'cerfvolant8@gmail.com'
SUBJECT = 'TEST MAIL'
TEXT = 'Here is a message from python.'
##########################################
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_sender, gmail_passwd)
BODY = '\r\n'.join(['To: %s' % TO,
'From: %s' % gmail_sender,
'Subject: %s' % SUBJECT,
'', TEXT])
try:
server.sendmail(gmail_sender, [TO], BODY)
print('email sent')
except:
print('error sending mail')
server.quit()