I have made a script in python to automatically open tickets on OTRS.
SERVER = "mailserver.domain"
FROM = "ZABBIX<zabbix@domain>"
SUBJECT = "{0}-{1}[ZABBIX] Do something".format(date,hour)
TO = ["otrs.ticket@domain"]
CC = someone@domain
BODY = "[{0}] Caracteres randomicos para evitar reabertura de chamado no OTRS\n\n\n".format(RANDOM)
REPLY = "dudeIT@domain"
Cmd = 'cat {2} | isql DATABASE01 {0} {1} -b -c -d, > {3}'.format(User,Pass,QuerySQL,FileTXT
Converte = 'unix2dos %s '% FileCSV
exec_query = os.system(Cmd)
tcsv = open(FileCSV,"wb")
ftxt = open(FileTXT, "rt")
for line in ftxt:
tcsv.write(line.replace(',',';'))
tcsv.close()
ftxt.close()
exec_converte = os.system(Converte)
TEXT = MIMEText(BODY.encode('latin-1'),'plain')
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = ', '.join(TO)
msg['Cc'] = CC
msg['reply-to'] = REPLY
destinatarios = TO + CC.split(",")
part = MIMEBase('application', "octet-stream")
part.set_payload(open(FileCSV,"rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment;
filename=List_Files.csv')`
msg.attach(part)
msg.attach(TEXT)
server = smtplib.SMTP(SERVER)
While testing the script (sorry for the errors of bad practices and etc), everthing was fine, the body (text message) and the attachment was ok. But when I send the email to OTRS. The text don't appear in body of ticket, instead the OTRS show the message: "no text message = > see attachment.
FOund the solution.
I can't figure out what cause the problem, but sending out the message as HTML solved the problem.
BODY = "<html>
<head></head>
<body>
<p>[{0}] Caracteres randomicos para evitar reabertura de chamado no OTRS
</body></html>".format(RANDOM)
...
TEXT = MIMEText(BODY,'html')