簡體   English   中英

KornShell(ksh)代碼用mailx和uuencode發送附件?

[英]KornShell (ksh) code to send attachments with mailx and uuencode?

我需要附上一個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"

有不同的方法來提供消息文本,這只是一個接近原始問題的示例。 如果消息應該重用,那么將它存儲在文件中並使用該文件是有意義的。

好吧,這是你遇到的前幾個問題。

  1. 您似乎假設郵件客戶端將處理沒有任何標頭的uuencoded附件。 這不會發生。

  2. 您正在濫用I / O重定向:uuencode的輸出和here-document都被送到mailx,這是不可能發生的。

  3. 你在濫用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

還有很多其他的可能性......但是這個仍然有你的例子中的here文檔,並且很容易脫離我的腦海,並且沒有涉及臨時文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM