Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
KornShell(ksh)代码发送带有mailx和uuencode的附件?_Shell_Unix_Scripting_Solaris_Ksh - Fatal编程技术网

KornShell(ksh)代码发送带有mailx和uuencode的附件?

KornShell(ksh)代码发送带有mailx和uuencode的附件?,shell,unix,scripting,solaris,ksh,Shell,Unix,Scripting,Solaris,Ksh,我需要附加一个文件与mailx,但目前我没有成功 这是我的代码: subject="Something happened" to="somebody@somewhere.com" body="Attachment Test" attachment=/path/to/somefile.csv uuencode $attachment | mailx -s "$subject" "$to" << EOF The message is ready to be sent with the

我需要附加一个文件与mailx,但目前我没有成功

这是我的代码:

subject="Something happened"
to="somebody@somewhere.com"
body="Attachment Test"
attachment=/path/to/somefile.csv

uuencode $attachment | mailx -s "$subject" "$to" << EOF

The message is ready to be sent with the following file or link attachments:

somefile.csv

Note: To protect against computer viruses, e-mail programs may prevent
sending or receiving certain types of file attachments.  Check your
e-mail security settings to determine how attachments are handled.

EOF
subject=“发生了什么事”
to=”somebody@somewhere.com"
body=“附件测试”
附件=/path/to/somefile.csv

uuencode$attachment | mailx-s“$subject”“$to”好吧,这里是您遇到的前几个问题

  • 您似乎假设邮件客户端将处理UU编码的附件,而不使用任何头。那不会发生

  • 您误用了I/O重定向:uuencode的输出和here文档都被馈送到mailx,这是不可能发生的

  • 您误用了uuencode:如果给定了一个路径,那么它只是给出解码文件的名称,而不是输入文件名。两次给出该文件将为解码文件指定与读取文件相同的名称。-m标志强制base64编码。但这仍然不能为mailx提供附件头

  • 你最好能得到一份mpack,它能满足你的需要

    如果你必须这样做,你可以这样做:

    cat <<EOF | ( cat -; uuencode -m /path/to/somefile.csv /path/to/somefile.csv; ) | mailx -s "$subject" "$to" 
    place your message from the here block in your example here
    EOF
    

    cat您必须同时包含您的邮件文本和UU编码的附件:

    $ subject="Something happened"
    $ to="somebody@somewhere.com"
    $ body="Attachment Test"
    $ attachment=/path/to/somefile.csv
    $
    $ cat >msg.txt <<EOF
    > The message is ready to be sent with the following file or link attachments:
    >
    > somefile.csv
    >
    > Note: To protect against computer viruses, e-mail programs may prevent
    > sending or receiving certain types of file attachments.  Check your
    > e-mail security settings to determine how attachments are handled.
    >
    > EOF
    $ ( cat msg.txt ; uuencode $attachment somefile.csv) | mailx -s "$subject" "$to"
    
    $subject=“发生了什么事”
    $to=”somebody@somewhere.com"
    $body=“附件测试”
    $attachment=/path/to/somefile.csv
    $
    $cat>msg.txt
    >somefile.csv
    >
    >注意:为了防止计算机病毒,电子邮件程序可能会阻止
    >发送或接收某些类型的文件附件。检查你的
    >电子邮件安全设置,以确定如何处理附件。
    >
    >EOF
    $(cat msg.txt;uuencode$attachment somefile.csv)| mailx-s“$subject”“$to”
    

    有不同的方式提供消息文本,这只是一个例子,接近您的原始问题。如果邮件需要重复使用,只需将其存储在文件中并使用此文件即可。

    非常感谢!是的,我看到有mutt-to可以做简单的附件,但由于我不是该框的根用户,我必须处理任何mailx黑客。我有以下错误:uuencode:非法选项--m用法:uuencode[infle]remotefileYou有和旧版本的uuencode,在它提供base64编码之前。。。你仍然可以得到mpack,然后在你的帐户下编译它以供本地使用。。。我可能会这么做。谢谢你的回复!那么msg.txt是由EOF创建的,然后在最后一行中重复使用?我的错!我已将猫的间距设置为>msg.txt