如何在正文消息中将变量(缺少文件($file从脚本传递到我的python电子邮件脚本。script.sh
#!/bin/bash
file = abc.txt
echo "the following" ${file} "are missing"
pythonEmail.py
pythonEmail.py
#!/usr/bin/python
import smtplib
sender = 'me@test.com'
receivers = ['you@test.com']
message = """From: myself<me@test.com>
To: you@test.com'
Subject: missing files
$file
"""
try:
smtpObj = smtplib.SMTP("localhost")
smtpObj.sendmail(sender, receivers, message)
print ("Successfully sent email")
except SMTPException:
print ("Error: unable to send email")
这只是@Haxiel评论的内容:
script.sh:
#!/bin/bash
file=abc.txt
echo "the following" ${file} "are missing"
pythonEmail.py $file
pythonEmail.py:
#!/usr/bin/python
import smtplib
import sys
sender = 'me@test.com'
receivers = ['you@test.com']
message = """
From: myself<me@test.com>
To: you@test.com
Subject: missing files
%s""" % (sys.argv[1])
try:
smtpObj = smtplib.SMTP("localhost")
smtpObj.sendmail(sender, receivers, message)
print ("Successfully sent email")
except SMTPException:
print ("Error: unable to send email")