-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_email.py
40 lines (34 loc) · 1.37 KB
/
send_email.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
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import Certificates.passwords as pw
from access_database import *
sender_email = "[email protected]"
password = pw.email_password
def send_email(user,subject,text,html):
if user["email"] != "":
message = MIMEMultipart("alternative")
message["subject"] = subject
message["From"] = "[email protected]"
message["To"] = user["email"]
message.attach(MIMEText(text,"plain"))
if html is not None:
message.attach(MIMEText(html,"html"))
context = ssl.create_default_context()
with smtplib.SMTP_SSL("mail.privateemail.com",465,context = context) as server:
server.login(sender_email,password)
server.sendmail(sender_email,user['email'],message.as_string())
def send_group_email(group,subject,text,html):
context = ssl.create_default_context()
with smtplib.SMTP_SSL("mail.privateemail.com",465,context = context) as server:
server.login(sender_email,password)
for user in get_group_users(group["id"]):
if user["email"] != "":
message = MIMEMultipart("alternative")
message["subject"] = subject
message["From"] = "[email protected]"
message["To"] = user["email"]
message.attach(MIMEText(text,"plain"))
if html is not None:
message.attach(MIMEText(html,"html"))
server.sendmail(sender_email,user['email'],message.as_string())