I'm rewriting a shell script to python and a part of it includes sending notifications via mailx.
I can't seem to get the subprocess right.
result = subprocess.run(["/bin/mailx", "-r", "sender@email.com", "-s", "Test", "recipient@email.com"], check=True)
When I run this on the server the command returns a blank row, "won't complete" and I thought it might be because mailx is waiting for the email body because when I try sending through bash without a body I get sort of the same problem, so I got these tips:
1.
result = subprocess.run(["echo", "Testing", "|", /bin/mailx", "-r", "sender@email.com", "-s", "Test", "recipient@email.com"], check=True)
and
2. result = subprocess.run(["/bin/mailx", "-r", "sender@email.com", "-s", "Test", "recipient@email.com", b"Testingtesting"], check=True)
When testing 1, it just echoes out everything after echo.
When testing 2, I get the blank row again.
question from:
https://stackoverflow.com/questions/65934654/mailx-wont-send-through-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…