Sendmailを使用して添付ファイルを追加する方法(制限付きオプション)?

Sendmailを使用して添付ファイルを追加する方法(制限付きオプション)?

ロックされたRHELボックスを使用しています。

目的は、添付ファイルを含む電子メールを送信することです。

利用可能な唯一のメールサービスはsendmailです。 (sendemail、mail、mailx、muttなどは使用できません。)

また、uuencodeコマンドが見つからず、sharutilsをインストールできません。

次の簡単なテストでsendmailが正しく機能していることを確認しました。

echo "Subject: testing" | sendmail -v [email protected]

次のコマンドを試しましたが、dead.letterのみが生成されます。

echo "Subject: testing" | sendmail /a /tmp/test.txt [email protected]

これらの制限を考慮して、sendmailを使用してサーバーからファイルを送信する正しい方法は何ですか?

ベストアンサー1

解決策は、次のようにopenssl base64エンコーディングを使用することです。

( echo "to: [email protected]"
  echo "subject: Message from the server"
  echo "mime-version: 1.0"
  echo "content-type: multipart/related; boundary=messageBoundary"
  echo
  echo "--messageBoundary"
  echo "content-type: text/plain"
  echo
  echo "Please find the document attached."
  echo
  echo "--messageBoundary"
  echo "content-type: text/plain; name=test.txt"
  echo "content-transfer-encoding: base64"
  echo
  openssl base64 < /tmp/test.txt) | sendmail -t -i

おすすめ記事