我在python中创建了一个脚本来自动打开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)
在测试脚本时(对于不良做法的错误等而感到抱歉),外观很好,正文(短信)和附件都没问题。但是当我将电子邮件发送给OTRS时。该文本不会显示在票证正文中,而是OTRS会显示以下消息:&#34; no text message =&gt;见附件。
答案 0 :(得分:0)
支持解决方案。
我无法找出导致问题的原因,但是以HTML格式发送消息解决了问题。
BODY = "<html>
<head></head>
<body>
<p>[{0}] Caracteres randomicos para evitar reabertura de chamado no OTRS
</body></html>".format(RANDOM)
...
TEXT = MIMEText(BODY,'html')