ssmtp cannot email my bash variable received from python subprocess

164 Views Asked by At

I'm using subprocess within a python script to send variables into a bash script which is designed to send emails.

My python code:

import re
import subprocess
message="https://example.com/"
subprocess.run(["./send_email.bash",message])

My "./send_email.bash" script:

#!/bin/bash
body=$1
echo "$body" | ssmtp [email protected]

It keeps sending a blank email. However, if I use a string which doesn't come from subprocess, the email contains it. There may be a better way of doing this, but the point of my post is to understand why this doesn't work. What perplexes me is that the variable sent from subprocess may be appended to a file. But, it cannot be recognized by loops or "if" expressions. etc.

Thank you!

1

There are 1 best solutions below

1
chr218 On

I should have been more specific. The "message" within my python code was an email address: "https://example.com/". It appears that when I remove the "https://" from the string, it works perfectly fine!