3

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

フィードバックをいただければ幸いです。


更新 毎回パスを使用する必要がないように、添付ファイル変数を追加しました。

4

2 に答える 2

3

メッセージのテキストとuuencodeされた添付ファイルの両方を連結する必要があります。

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

メッセージテキストを提供する方法はいくつかありますが、これは元の質問に近い例にすぎません。メッセージを再利用する必要がある場合は、メッセージをファイルに保存してこのファイルを使用するのが理にかなっています。

于 2008-09-18T20:35:21.627 に答える
1

さて、ここにあなたが持っている最初のいくつかの問題があります。

  1. メールクライアントがヘッダーなしでuuencodeされた添付ファイルを処理することを想定しているようです。それは起こりません。

  2. I / Oリダイレクトを誤用しています。uuencodeの出力とヒアドキュメントの両方がmailxにフィードされていますが、これは発生しません。

  3. uuencodeを誤用しています。1つのパスが指定されている場合、それはデコードされたファイルを指定するための名前であり、入力ファイル名ではありません。ファイルに2回指定すると、読み取られたファイルと同じ名前がデコードされたファイルに割り当てられます。-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

他にもたくさんの可能性があります...しかし、これはあなたの例のようにヒアドキュメントをまだ持っていて、頭のてっぺんから簡単で、一時ファイルは含まれていません。

于 2008-09-18T20:33:30.757 に答える