Skip to content
Snippets Groups Projects
Commit 6ae18305 authored by Boman Romain's avatar Boman Romain
Browse files

Merge branch 'bigmail' into 'master'

truncate large e-mails

See merge request am-dept/linuxbin!40
parents 20f6a3f4 6778cd2e
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#from future import standard_library import sys, os, os.path, socket, platform, fnmatch
#standard_library.install_aliases() import subprocess, string, re
import sys, os, os.path, shutil, socket, platform, glob, fnmatch
import datetime, tarfile, subprocess, string, re
from prmClasses import * from prmClasses import *
# -- Base Class ---------------------------------------------------------------- # -- Base Class ----------------------------------------------------------------
...@@ -64,10 +62,14 @@ class ParametricJob(PRMSet): ...@@ -64,10 +62,14 @@ class ParametricJob(PRMSet):
f.close() f.close()
except: except:
text="file not found" text="file not found"
maxsize = 5*1024*1024
if(len(head+text)>maxsize):
text = text[:maxsize]
text+=f'\n\n[message truncated - see file={file}]\n'
import smtplib import smtplib
server = smtplib.SMTP(smtpServ) server = smtplib.SMTP(smtpServ)
server.sendmail(fromA, toA, (head+text).encode('ascii','ignore')) server.sendmail(fromA, toA, (head+text).encode('ascii','ignore'))
#server.sendmail(fromA, toA, head+text)
server.quit() server.quit()
def mailhtml(self, file, subject): def mailhtml(self, file, subject):
...@@ -75,7 +77,6 @@ class ParametricJob(PRMSet): ...@@ -75,7 +77,6 @@ class ParametricJob(PRMSet):
# getting address & smtp servers # getting address & smtp servers
fromA, toA, smtpServ = self.getMailData() fromA, toA, smtpServ = self.getMailData()
# building email # building email
#from email.MIMEText import MIMEText
from email.mime.text import MIMEText from email.mime.text import MIMEText
file = open(file,'r') file = open(file,'r')
text = file.read() text = file.read()
...@@ -105,9 +106,7 @@ class ParametricJob(PRMSet): ...@@ -105,9 +106,7 @@ class ParametricJob(PRMSet):
mail['From'] = fromA mail['From'] = fromA
mail['To'] = toA mail['To'] = toA
mail['Subject'] = subject mail['Subject'] = subject
#mail.preamble = 'Battery result in attachement \n'
machineName = socket.gethostname() machineName = socket.gethostname()
#from email.MIMEText import MIMEText
from email.mime.text import MIMEText from email.mime.text import MIMEText
text = "Battery result on %s in attachement ...\n" % machineName text = "Battery result on %s in attachement ...\n" % machineName
msg = MIMEText(text, 'html','iso-8859-1') msg = MIMEText(text, 'html','iso-8859-1')
...@@ -131,6 +130,7 @@ class ParametricJob(PRMSet): ...@@ -131,6 +130,7 @@ class ParametricJob(PRMSet):
print("file %s correctly closed after mailing" % fileName) print("file %s correctly closed after mailing" % fileName)
except smtplib.SMTPException: except smtplib.SMTPException:
text="file %s not found"%fileName text="file %s not found"%fileName
# Encode the payload using Base64 # Encode the payload using Base64
encoders.encode_base64(msg) encoders.encode_base64(msg)
(head, tail) = os.path.split(fileName) (head, tail) = os.path.split(fileName)
...@@ -205,7 +205,7 @@ class ParametricJob(PRMSet): ...@@ -205,7 +205,7 @@ class ParametricJob(PRMSet):
nodeHost = socket.gethostname() nodeHost = socket.gethostname()
filename = self.rmNodeResultsScriptName(jobId) filename = self.rmNodeResultsScriptName(jobId)
localNodeDir = self.getLocalDiskDir(jobId) localNodeDir = self.getLocalDiskDir(jobId)
#write file # write file
file=open(filename,"w") file=open(filename,"w")
file.write("#!/usr/bin/env python3\n") file.write("#!/usr/bin/env python3\n")
#sshRmCmd = 'ssh %s "rm -rf %s"' % (nodeHost, localNodeDir) #sshRmCmd = 'ssh %s "rm -rf %s"' % (nodeHost, localNodeDir)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment