0

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 example@gmail.com

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!

chr218
  • 19
  • 5
  • Why don't you run `ssmtp` directly and feed the mail into its `stdin`? Or just use the `stmp` module to do what `ssmtp` does? – Klaus D. Jan 19 '20 at 18:33
  • I did, it works. But I'm itching to figure out why this doesn't work. Thanks! – chr218 Jan 19 '20 at 18:46
  • 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! – chr218 Jan 20 '20 at 04:06

1 Answers1

0

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!

chr218
  • 19
  • 5