-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendemail.py
34 lines (26 loc) · 898 Bytes
/
sendemail.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
import smtplib
email = "USERS EMAIL"
first_name = "USERS FIRST NAME"
msg = "HTML/TEXT MESSAGE"
def send_email(subject, message):
from smtplib import SMTP_SSL as SMTP
from email.mime.text import MIMEText
sender = 'FROM_EMAIL'
destination = ['TO_EMAIL', email] #send to 2 emails
password = 'PASSWORD_FOR_FROM_EMAIL_ACCOUNT'
SMTPserver = 'smtpout.secureserver.net:465'
try:
msg = MIMEText(message, 'html')
msg['Subject']= subject
msg['From'] = sender
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(sender, password)
try:
conn.sendmail(sender, destination, msg.as_string())
print("Mail sent to %s" % (destination))
finally:
conn.quit()
except Exception as exc:
print( "mail failed; %s" % str(exc) )
send_email("Update Credentials", msg)