forked from asmbly-makerspace/NeonIntegrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmailUtil.py
More file actions
22 lines (17 loc) · 964 Bytes
/
Copy pathgmailUtil.py
File metadata and controls
22 lines (17 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import smtplib, ssl, logging
from config import G_user, G_password
#################################################################################
# Sent a MIME email object to its recipient using GMail
#################################################################################
def sendMIMEmessage(MIMEmessage):
if not "@" in MIMEmessage['To']:
raise ValueError("Message doesn't have a sane destination address")
MIMEmessage['From'] = "Asmbly AdminBot"
logging.debug(f'''Sending email subject "{MIMEmessage['Subject']}" to {MIMEmessage['To']}''')
context = ssl.create_default_context()
try:
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(G_user, G_password)
server.sendmail(G_user, MIMEmessage['To'], MIMEmessage.as_string())
except:
logging.exception(f'''Failed sending email subject "{MIMEmessage['Subject']}" to {MIMEmessage['To']}''')