【发布时间】:2020-11-27 11:42:59
【问题描述】:
有一个程序在 linux 级别发出以下命令
EXE1= "SH -c '/usr/lib/sendmail ":EMAIL<1,X>:' < "/thisdata/level1/VRE/&HOLD&/':PC.FILE:'.CSV':'"':"'"
是否可以在此指令中附加第二个 PC.File?
【问题讨论】:
有一个程序在 linux 级别发出以下命令
EXE1= "SH -c '/usr/lib/sendmail ":EMAIL<1,X>:' < "/thisdata/level1/VRE/&HOLD&/':PC.FILE:'.CSV':'"':"'"
是否可以在此指令中附加第二个 PC.File?
【问题讨论】:
对此最正确的答案需要了解操作系统和您可能拥有的任何邮件服务器限制,但我一直在研究我们的旧例程,可能会提供一些见解。
我们曾经按照@RedCabbage 的建议使用 uuencode,但我们遇到了一些服务器拒绝消息的问题。由于我们无法控制其他人的服务器,并且由于 uuencode 几乎和泥土一样古老,我们更新了我们的解决方案以改用 MIME。见“不那么简单”
简单的方法
在我们的 Linux 系统上,我们使用 mailx(在我们的例子中链接到 /usr/bin/mail)来添加多个附件。
echo "It's Wednessday, my dudes." |mail -s "foobar" -a foo.txt -a bar.txt dudes@wednessday.com
如果文件路径正确(如果使用真实地址),这将生成一封带有两个附件和消息正文的电子邮件。
不那么容易
创建您自己的 MIME(多部分/混合)消息。我们创建一个类似的记录。
To: foo@foo.bar
From: bar@foo.bar
Subject: Not Rocket Surgery
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="SomelongBoundryMarkerYouMakeUpDoNotUseThis"
This is a multipart message in MIME format.
--SomelongBoundryMarkerYouMakeUpDoNotUseThis
Content-Type: text/plain
The body of that message go here.
--SomelongBoundryMarkerYouMakeUpDoNotUseThis
Content-Type: application/pdf
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename="YourFileName.pdf"
Content-Base: http://www.IputOurDomainHereDunnoWhyDoNotUseThis.com
##BASE64 encoded string go here.
--SomelongBoundryMarkerYouMakeUpDoNotUseThis
Rinse and Repeat with more files, newlines are important here.
对于编码部分,假设你的文件在 /foo/bar.pdf
ENCODED = ""
FILE.LOC = "/foo/bar.pdf"
TEST = ENCODE("Base64",1,FILE.LOC,2,ENCODED,1)
IF TEST EQ 0 THEN
;*Put the text in ENCODED where it says ##BASE64 encoded string go here
END
这更加乏味,因为您必须弄清楚所有的 mime 类型并确保所有内容的格式都正确。
祝你好运
【讨论】:
这就是我们管理多个附件的方式。例如,/home/jbloggs/attachment1.doc/home/jbloggs/attachment2.pdf。
您将(就像您所做的那样)必须构建命令并使用SH -c 'blah' 执行它们(就像您已经完成的那样。)
/home/jbloggs/tempemail.txt
To: recipient.email@gmail.com subject: Your subject line here This is the main body text
uuencode 以增加名称(此处为ENCODEDn):uuencode /home/jbloggs/attachment1.doc attachment1.doc > ENCODED1 uuencode /home/jbloggs/attachment2.pdf attachment2.pdf > ENCODED2
cat 将所有文件合并为一个文件:cat /home/jbloggs/tempemail.txt ENCODED1 ENCODED2 > COMBOFILE
sendmail:sendmail recipient.email@gmail.com < COMBOFILE
您可以循环访问任意数量的ENCODEDn 文件。
【讨论】: