-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.py
53 lines (40 loc) · 1.29 KB
/
test4.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
SMTPserver = 'smtp.gmail.com'
sender = '[email protected]'
destination = ['[email protected]']
USERNAME = "[email protected]"
PASSWORD = "Vecv5*MapuFixw"
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
content="""\
Test message
"""
import sys
import os
import subprocess
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
file_name = resource_path(os.path.dirname(os.path.abspath("test4.py"))) + "/test.txt"
subprocess.Popen('kate ' + file_name, shell=True)
subject="Sent from Python"
import sys
import os
import re
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
# old version
# from email.MIMEText import MIMEText
from email.mime.text import MIMEText
msg = MIMEText(content, text_subtype)
msg['Subject']= 'hello'
msg['From'] = sender # some SMTP servers will do this automatically, not all
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.quit()