You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1011 B
33 lines
1011 B
import smtplib
|
|
import os
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.base import MIMEBase
|
|
from email.mime.text import MIMEText
|
|
from email.utils import COMMASPACE, formatdate
|
|
from email import encoders
|
|
|
|
|
|
def EESendMail(send_from, send_to, subject, text, files, server="localhost",
|
|
port=587, username='', password='', isTls=True):
|
|
msg = MIMEMultipart()
|
|
msg['From'] = send_from
|
|
msg['To'] = send_to
|
|
msg['Date'] = formatdate(localtime=True)
|
|
msg['Subject'] = subject
|
|
|
|
msg.attach(MIMEText(text))
|
|
|
|
for f in files:
|
|
part = MIMEBase('application', "octet-stream")
|
|
part.set_payload(open(f, "rb").read())
|
|
encoders.encode_base64(part)
|
|
part.add_header('Content-Disposition', 'attachment; filename="{0}"'
|
|
.format(os.path.basename(f)))
|
|
msg.attach(part)
|
|
|
|
smtp = smtplib.SMTP(server, port)
|
|
if isTls:
|
|
smtp.starttls()
|
|
|
|
smtp.sendmail(send_from, send_to, msg.as_string())
|
|
smtp.quit()
|
|
|