#author("2019-08-09T16:10:52+09:00","default:dex","dex")
#author("2024-02-13T14:11:14+09:00","default:dex","dex")
#contents

*Mail [#g38b41af]

記事:
- [[古い技術について—SMTP現代事情つまみ食い— - Speaker Deck:https://speakerdeck.com/azumakuniyuki/gu-iji-shu-nituite-smtpxian-dai-shi-qing-tumamishi-i]]


----
** mailx: cliでメール送信テスト [#jc185394]

- CentOS 7.x: sendgridを使って送信テストする場合
#geshi(bash){{
sudo yum install mailx

EMAIL_TO=your@example.com
EMAIL_FROM=no-reply@example.com
read -sp "Enter smtp_password: " smtp_password

echo -e "test message from $(hostname -f)." \
| mailx -s "[test] subject $(date --iso-8601=seconds)" \
-S "smtp=smtp://smtp.sendgrid.net:587" \
-S "smtp-auth-user=apikey" \
-S "smtp-auth-password=$smtp_password" \
-S "from=$EMAIL_FROM" \
"$EMAIL_TO"
}}

- 記事
-- [[SMTPサーバのメール送信テストにmailxコマンドを使う | DevelopersIO:https://dev.classmethod.jp/cloud/aws/using-mailx/]]

----
** メールのスレッド化 [#q6c54177]

- https://tools.ietf.org/html/rfc2822#appendix-A.2
> Note especially the "Message-ID:", "References:", and "In-Reply-To:"

- スレッド元として「Message-Id:」にユニークIDを付ける。
- 「In-Reply-To:」と「References:」ヘッダに、スレッド元の「Message-Id:」を入れる。


- 記事
-- [[メールをメーラー上でスレッド表示する方法 - Qiita:https://qiita.com/yuku_t/items/a257dac96eac1ab912aa]]
-- [[関連するメールのスレッド化 | Opentone Labs.:http://labs.opentone.co.jp/?p=5654]]

----
** カスタムヘッダを付けて送信 [#v6e4ebd1]

- 例: スレッド化用のヘッダを追加する
#geshi(bash){{
#!/bin/bash

RECIPIENT=example@example.com
MESSAGE_ID=unique-string-example@example.com

/usr/sbin/sendmail -i --  $RECIPIENT<<EOD
To: <$RECIPIENT>
Subject: Test Message
In-Reply-To: ${MESSAGE_ID}
References: ${MESSAGE_ID}

Body of the message line 1
Body of the message line 2
EOD
}}


----
**添付ファイル付きメール送信 [#vfb348f3]

-記事
--[[特集「Muttにしよう!」(PDF):http://www.emaillab.org/mutt/linuxjapan/200106-mutt.pdf]]

-Gmailでも表示できるスクリプト
#geshi(bash){{
sudo yum install mutt sharutils

cat > gmail.sh << 'EOS'
#!/bin/bash
# encoding: utf-8

readonly CUR_DIR=$(cd $(dirname $0);pwd)
mail_to='bar@example.com'
mail_from='foo <foo@example.com>'
subject='メール件名'
body='メール本文
テスト'
attachment_file=$CUR_DIR/`basename $0`

export EMAIL=$mail_from
export LANG=ja_JP.UTF-8
echo "${body}" | mutt -n -s "${subject}" "${mail_to}" -a "${attachment_file}"

# vim: ts=4:sw=4
EOS
}}

-FROMヘッダの指定。環境変数に書くか、~/.muttrc に追加
#geshi(bash){{
export EMAIL="foo <foo@example.com>"

vi ~/.muttrc
----
set envelope_from=yes
set from="from@address"
----
}}

----
**root宛のメールを転送する [#a29dc87d]

-postfixを使っている場合
 # sed -i '/^root:/d' /etc/postfix/aliases
 # echo "root: hoge@example.com" >> /etc/postfix/aliases
 # postalias /etc/postfix/aliases
 # echo test|mail root
--postaliasでエラーが出る場合、/etc/postfix/main.cf の"myhostname"の値を設定してあるか確認。

-sendmailを使っている場合
 # sed -i '/^root:/d' /etc/aliases
 # echo "root: hoge@example.com" >> /etc/aliases
 # newaliases
 # echo test|mail root



----
**肥大化したメールの削除 [#y33f73e8]

#geshi(bash){{
cat /dev/null > /var/spool/mail/root
}}

----
**logwatchメールの停止 [#m333d12b]

-記事
--[[@IT:rootあてに来るシステムチェックのメールを止めるには:http://www.atmarkit.co.jp/flinux/rensai/linuxtips/336stoprootmail.html]]

-CentOS5.x
#geshi(bash){{
chmod -x /etc/cron.daily/0logwatch
}}

----
**メール送信ができない時は [#t0c47783]

-以下のエラーの場合は
 WARNING: RunAsUser for MSP ignored, check group ids (egid=500, want=51)
 can not chdir(/var/spool/clientmqueue/): Permission denied
 Program mode requires special privileges, e.g., root or TrustedUser.
--SGIDが必要な模様なので付加。
 # chmod g+s /usr/sbin/sendmail.sendmail
--参考URL:http://www.webservertalk.com/message1453726.html

-postdrop warningの時は~
以下のエラーの際は、postfix が起動していないため発生するようです。~
 postdrop: warning: unable to look up public/pickup: No such file or directory
--解決方法~
プロセスの確認。masterが存在すれば起動済み~
 # ps -aux | grep postfix
 root     26348  0.2  0.1  5220 1632 ?        S    17:02   0:00 /usr/libexec/postfix/master
起動していない場合は、起動させる。~
 # service postfix start
 # chkconfig postfix on
ためしにメールを送ってみる。~
 # echo "hogehoge" | mail メールアドレス

----

**majordomo(メーリングリスト) [#sb1d87e0]

以下のように「majordomo@ドメイン名」宛にコマンドを送ると結果が返される。~
 宛先:majordomo@ドメイン名
 件名:(何でも構いません)
 本文:
      コマンド
      コマンド
      ・・・
      コマンド
      end (or "-")

-コマンド~
|コマンド名|説明|h
|help|説明ページの入手|
|lists |公開されたメーリングリスト一覧|
|lists 自分のメールアドレス|自分に配信されるメーリングリスト一覧|

-リンク
--[[Majordomo運用手引書>http://www.infoscience.co.jp/technical/majordomo/]]

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS