-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmtp_server_script.py
45 lines (37 loc) · 923 Bytes
/
smtp_server_script.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
import smtplib
#SMTP server start
smtp_server = ''
port = 587 #port for emails and SSL protocol
myServer = smtplib.SMTP(smtp_server, port) #initialize server
#host email and password
host_email = ''
password = ''
#client email
client_email = ''
#start SMTP server
try:
myServer.starttls()
print('[Server Started]')
except Exception as e:
print(f'Error {e}')
exit()
#log in to email
try:
myServer.login(host_email, password)
print('Login successful')
except Exception as e:
print(f'Could not log into host email {e}')
exit()
#compose email
subject = input('Subject of Email: ')
body = input('What Do You Want to Say?: ')
composed_email = f'Subject: {subject}\n\n{body}'
#send email
try:
myServer.sendmail(host_email, client_email, composed_email)
print('Email Sent!')
except Exception as e:
print(f'Email failed to send {e}')
exit()
#close server
myServer.quit()