gpt4 book ai didi

shell - 使用 mailx 和 uuencode 发送附件的 KornShell (ksh) 代码?

转载 作者:行者123 更新时间:2023-12-04 18:23:51 25 4
gpt4 key购买 nike

我需要用 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

如有任何反馈,我们将不胜感激。


更新我添加了附件 var 以避免每次都必须使用该路径。

最佳答案

您必须同时连接消息文本和 uuencoded 附件:

$ 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"

提供消息文本的方式有多种,这只是一个与您的原始问题接近的示例。如果消息应该被重用,将它存储在一个文件中并使用这个文件是有意义的。

关于shell - 使用 mailx 和 uuencode 发送附件的 KornShell (ksh) 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/96326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com