import subprocess
to ='xxxx@fmr.com'
subject= 'hostname'
cmd= "cat /var/log | mailx -s 'swap is full on'+subject" +to
subprocess.Popen(cmd,shell=True)
如果我在主题前放置双引号,则 mailx 将第一个字符作为主题并将其他字符视为收件人并尝试向他们发送邮件。
--------------------cmd= "cat/var/log | mailx -s 'swap is full on'"+subject +to< 的输出/h1>
最佳答案
你能试试这个吗:
import subprocess
to ='xxxx@fmr.com'
cmd= "cat /var/log | mailx -s 'test' " + to
subprocess.Popen(cmd,shell=True)
关于python - 我正在尝试使用 shell 命令在 python 中发送邮件。但变量不会在脚本中被替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915722/