0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mail(mailx)コマンドでファイル内容をbodyにしてメール送信したら失敗

Posted at

発生した問題

これまで mail(mailx) コマンドでメールを送信する場合は、ファイルに書き出した内容を読み込んだデータを body にして、送信していた。
気づいたら、メールに .dat なファイルが添付されるようになってしまっていた。
これは何が原因なのかを調査した結果をまとめる。

結論

body の内容を書き出したファイルの改行コードが dos になっていたのが原因。
以下措置を行う。

メール本文ファイルの改行コード変換
nkf -Lu --overwrite mailbody.txt;

備考

結果として以下は不要。

修正前
_rc=$(mail -s "表題:テストメール" "送信先アドレス" < "メール本文ファイル" 2> /dev/null; echo $?)
修正後
export LC_CTYPE=ja_JP.UTF-8
_rc=$(cat -v "メール本文ファイル"  | mail -s "表題:テストメール" "送信先アドレス" 2> /dev/null; echo $?)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?