WindowsとMacの両方でローカル配信メールを設定する方法

ローカルからアプリケーションがメール投げようとすると何も設定してないとエラーになっちゃいますよね。 私の職場じゃWindowsMac使っている人が半々なのですが、どちらの環境でもこのメールの問題を解決したので書いてみます。

Windowsの場合

簡単です。 smtp4devをダウンロードして起動するだけで25ポートをlistenしてくれます。 あとはアプリがメール投げたらこの子がそれを拾ってくれるようになります。

smtp4dev.codeplex.com

Macの場合

Macの場合は、OSがUnix系なので、postfixを設定します。 設定をすると/Users/{username}/Maildir/の配下にメールが届くようになります。 こんな感じ。

# command : create setting file for postfix
$ sudo vi /etc/postfix/aliases.reg

## discription
/(?!^root$|^{username}$)^.*$/ {username}

# command : create setting file for postfix
$ sudo vi /etc/postfix/transport_maps

## discription
/^.*@.*$/ local

# command : modify setting file for postfix
$ sudo vi /etc/postfix/main.cf

## discription
#local_recipient_maps =#local_recipient_maps =
local_recipient_maps =

#alias_maps = netinfo:/aliases#alias_maps = netinfo:/aliases
alias_maps = hash:/etc/postfix/aliases,regexp:/etc/postfix/aliases.reg

#home_mailbox = Mailbox#home_mailbox = Mailbox
home_mailbox = Maildir/

#luser_relay = admin+$local#luser_relay = admin+$local
luser_relay = {username}

# add following description to bottom line
transport_maps = pcre:/etc/postfix/transport_maps

# command : create aliases's binaly file
$ sudo postalias /etc/postfix/aliases

# command : reflect
$ sudo postfix reload

{username}は各自のユーザ名に置き換えてください。

postfixが起動してないとsudo postalias /etc/postfix/aliasesの箇所でエラーになります。

その場合は、sudo postfix startしてあげてください。

参考にしたサイトはこちら。

https://blog.tagbangers.co.jp/ja/2015/05/22/setting-of-local-e-mail-for-mac

http://open-groove.net/postfix/mail-forward/