Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux sendmail向电子邮件添加第二个附件_Linux_Sendmail_Universe - Fatal编程技术网

Linux sendmail向电子邮件添加第二个附件

Linux sendmail向电子邮件添加第二个附件,linux,sendmail,universe,Linux,Sendmail,Universe,有一个在linux级别发出以下命令的程序 EXE1= "SH -c '/usr/lib/sendmail ":EMAIL<1,X>:' < "/thisdata/level1/VRE/&HOLD&/':PC.FILE:'.CSV':'"':"'" EXE1=“SH-c'/usr/lib/sendmail”:电子邮件:'

有一个在linux级别发出以下命令的程序

EXE1= "SH -c '/usr/lib/sendmail ":EMAIL<1,X>:' < "/thisdata/level1/VRE/&HOLD&/':PC.FILE:'.CSV':'"':"'"
EXE1=“SH-c'/usr/lib/sendmail”:电子邮件:'

是否可以在此说明中附加第二个PC.文件?

这就是我们管理多个附件的方式。例如,
/home/jbloggs/attachment1.doc
/home/jbloggs/attachment2.pdf

您将(正如您所做的)必须构建命令并使用
SH-c'blah'
执行它们(正如您已经做的那样)

  • 创建一个包含地址、主题和正文的文本文件(例如)
    /home/jbloggs/tempemail.txt
  • 在附件和
    uuencode
    之间循环,将其命名为递增名称(
    ENCODEDn
    此处):
  • 使用
    cat
    将所有文件合并为一个文件:
  • 在组合框上使用
    sendmail
  • sendmail收件人。email@gmail.com

    你可以循环浏览任意多个
    ENCODEDn
    文件。

    最正确的答案需要了解操作系统和任何邮件服务器限制,但我一直在使用我们的一个老例程,这可能会提供一些见解

    我们曾经按照@redcolla的建议进行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类型,并确保所有内容的格式都正确

    祝你好运

    sendmail recipient.email@gmail.com < COMBOFILE
    
    echo "It's Wednessday, my dudes." |mail -s "foobar" -a foo.txt -a bar.txt dudes@wednessday.com
    
    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.
    
    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