· 6 years ago · Oct 23, 2019, 03:42 AM
1import sys
2import config
3import requests
4import time
5theIPAddress = ""
6memIPAddress = ""
7
8USERNAME = config.username + "@gmail.com"
9PASSWORD = config.password
10
11def send_email(user, pwd, recipient, subject, body):
12
13 FROM = user
14 TO = recipient if type(recipient) is list else [recipient]
15 SUBJECT = subject
16 TEXT = body
17
18 # Prepare actual message
19 message = """From: %s\nTo: %s\nSubject: %s\n\n%s
20 """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
21 try:
22 server = smtplib.SMTP("smtp.gmail.com", 587)
23 server.ehlo()
24 server.starttls()
25 server.login(user, pwd)
26 server.sendmail(FROM, TO, message)
27 server.close()
28 print 'successfully sent the mail'
29 except:
30 print "failed to send mail"