发送了多个带有“ cmd = echo ...”的附件

时间:2019-07-01 11:20:01

标签: python linux subprocess echo

我使用以下代码从linux发送邮件-我通常只附加一个文件,但想更改编码以输入五个文件-怎么知道?

body_text = "This is your Email Body"
title = "This is your Email title"
file = ('location/filename.txt')
cmd = 'echo "'+body_text+'" | mutt -s "'+title+'" -a '+file+' -- email@address.com'
subprocess.call(cmd,shell=True)

我读了很多网站,但是没有一个使用我的代码。 谁能帮我吗?

1 个答案:

答案 0 :(得分:1)

需要附加多个文件时,Mutt需要多个-a

https://superuser.com/questions/257963/using-mutt-to-send-2-files

body_text = "This is your Email Body"
title = "This is your Email title"
files = ('location/filename.txt', 'other file.txt')
cmd = 'echo "'+body_text+'" | mutt -s "'+title+ '" -a '.join(files) +' -- email@address.com'
subprocess.call(cmd,shell=True)