2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MIMEメールを組み立てて標準出力するだけのコマンドを作った

CLI やスクリプトからメールを送りたい場面は今でもありますが、
MIME メールの生成と SMTP 送信が一体化していることに、少し違和感がありました。

そこで、MIME メールを組み立てて stdout に出すだけのコマンドラインツールを作りました。

mime-email

mime-email は、標準入力や引数から MIME 形式のメールを生成し、stdout に出力する CLI ツールです。
組み立てのみで、送信は行いません。

echo "mail body" \
  | mime-email \
      --from me@example.com \
      --to "山田 太郎 you@example.com" \
      --subject "test" \
      --attach "file.xlsx"

必要であれば、

... | msmtp -t

のように後段で送信します。

なぜ送らないのか

メール生成とメール送信は別の関心事だからです。

stdout に出すだけにすると、

  • 生成結果をそのまま確認できる
  • Unix 的に他のツールと組み合わせられる
  • SMTP 設定から完全に切り離せる

という利点があります。

こんな用途向け

  • cron / CI からの簡単な通知
  • 添付付きメールの自動生成
  • 既存の SMTP 環境をそのまま使いたい場合

万人向けではありませんが、
「メールをデータとして扱いたい」人には便利なツールだと思います。

リンク

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?