-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmpt_sender.py
41 lines (32 loc) · 965 Bytes
/
smpt_sender.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
# SMPT Email Sender
import smtplib
import secret
# Config and Content
MY_ADDRESS = secret.ADDRESS
USERNAME = secret.USERNAME
PASSWORD = secret.PASSWORD
HOST = secret.HOST
PORT = secret.PORT
RECIEVER_ADDRESS = secret.RECIEVER_ADDRESS
SUBJECT = secret.SUBJECT
CONTENT = secret.CONTENT
def main():
# set up the SMTP server
s = smtplib.SMTP(host=HOST) # Add as parameter if required by mail server: port=PORT
s.starttls()
s.ehlo()
s.login(USERNAME, PASSWORD)
# For each contact, send the email:
BODY = '\r\n'.join(['To: %s' % RECIEVER_ADDRESS,
'From: %s' % MY_ADDRESS,
'Subject: %s' % SUBJECT,
'', CONTENT])
try:
s.sendmail(MY_ADDRESS, [RECIEVER_ADDRESS], BODY)
print('email sent')
except:
print('error sending mail')
# Terminate the SMTP session and close the connection
s.quit()
if __name__ == '__main__':
main()