-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMPT.py
37 lines (32 loc) · 1.22 KB
/
SMPT.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
import smtplib
def send_email(user, pwd, recipient, subject, body):
gmail_user = user
gmail_pwd = pwd
sender = user
receiver = recipient if type(recipient) is list else [recipient]
email_subject = subject
email_text = body
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (sender, ", ".join(receiver), email_subject, email_text)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(sender, receiver, message)
server.close()
print ('successfully sent the mail')
except:
print ("failed to send mail")
def _sendEmailToUsers(users,course):
# SMTP_SSL Example
server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
server_ssl.ehlo() # optional, called by login()
server_ssl.login("[email protected]", "Smtptestemail")
# ssl server doesn't support or need tls, so don't call server_ssl.starttls()
for user in users:
server_ssl.sendmail("[email protected]", user, course + ' has just opened up a spot!')
print 'sent email to ' + user
#server_ssl.quit()
server_ssl.close()