gau1991
10 years ago
1 changed files with 33 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||
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() |
Loading…
Reference in new issue