HP-UXのシェルスクリプトを使用して、添付ファイルとしてテキストファイルを含む電子メールを送信する必要があります。muttをインストールしていません。
次のコマンドを使用していますが、ファイルの内容をメールの本文で送信します。添付ファイルとして使用します。
mailx -s "Report" name@example.com < file.txt
ksh
私は数年前にこの関数を書きました
# usage: email_attachment to cc subject body attachment_filename
email_attachment() {
to="$1"
cc="$2"
subject="$3"
body="$4"
filename="${5:-''}"
boundary="_====_blah_====_$(date +%Y%m%d%H%M%S)_====_"
{
print -- "To: $to"
print -- "Cc: $cc"
print -- "Subject: $subject"
print -- "Content-Type: multipart/mixed; boundary=\"$boundary\""
print -- "Mime-Version: 1.0"
print -- ""
print -- "This is a multi-part message in MIME format."
print -- ""
print -- "--$boundary"
print -- "Content-Type: text/plain; charset=ISO-8859-1"
print -- ""
print -- "$body"
print -- ""
if [[ -n "$filename" && -f "$filename" && -r "$filename" ]]; then
print -- "--$boundary"
print -- "Content-Transfer-Encoding: base64"
print -- "Content-Type: application/octet-stream; name=$filename"
print -- "Content-Disposition: attachment; filename=$filename"
print -- ""
print -- "$(perl -MMIME::Base64 -e 'undef $/; open $fh, shift; print MIME::Base64::encode(<$fh>); close $fh; ' $filename)"
print -- ""
fi
print -- "--${boundary}--"
} | /usr/lib/sendmail -oi -t
}
uuencode
あなたの友達です。
テスト済みの例を次に示します。
(uuencode .vimrc vimrc.txt; uuencode .zshrc zshrc.txt; echo Here are your attachments) | mailx -s 'Mail with attachments' email_address
私も数ヶ月前に同じ問題に遭遇しました。
私が必要としたコマンドはux2dos
( cat message_content_file; ux2dos file.txt | uuencode file.txt file.txt ) | mailx -m -s "subject" -r mail@sender mail@recipient
それが役立つことを願っています!
よろしく
uuencode の出力が添付ファイルではなくメッセージ本文の一部として送信されるという同じ問題がありました (少なくとも Outlook 2010 を使用して送信メールを表示する場合)。このスレッドで答えを見つけましたhttp://www.unix.com/hp-ux/41306-sending-attachments-through-mailx.html
-m を追加すると、mailx は電子メールの送信時に MIME ヘッダー行を追加しません。OP のコマンドは次のように変更されます。
mailx -m -s "Report" name@example.com < file.txt