Ich habe hunger

あふりかエンジニア、アフリカ向けのB2BのSaaSを開発する

Mac上でPostfix起動させて、Gmail経由でメール送ってみる。

そういや、自前のMacでPostfix動かしたことないな、と思って動かしてみた。


とりあえずのpostfixを起動してみた。

sudo postfix start
Password:
postfix: fatal: chdir(/Library/Server/Mail/Data/spool): No such file or directory

なんだこれ?と思ってみると
そもそも Libraryディレクトリ直下にServerとかないし:;(∩´﹏`∩);:

ないフォルダ作れよってStackOverFlowに書いてたので
作って起動したみたら・・・

/Library $ “sudo mkdir -p /Library/Server/Mail/Data/spool
Password:
/Library $ “sudo postfix start
postfix/postfix-script: warning: group or other writable: /Library/Server/Mail/Data/mta
postfix/postfix-script: starting the Postfix mail system
/Library $ “

ディレクトリの権限について、やいやい言われたので権限の修正。
postfix checkでエラーを確認できるので、それでエラーが出ないことを確認。

/Library $ “sudo chmod g-w /Library/Server/Mail/Data/mta
/Library $ “sudo postfix check
/Library $ “

とりあえず、これでPostfixの起動はできた状態に。

次に、postfixの設定ファイルをいじってGmailと繋げまっすー。
設定ファイルは postfix/main.cf なので、適当に探してください。

# Gmail
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash: /etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_use_tls = yes
tls_random_source=dev: /dev/urandom

そこにこんな感じで、設定ファイルに書き込んで、再び
postfix check で、エラーが出ないか再度確認。

確認ができたら、パスワードとか書くファイルを
/etx/postfix/ 内に生成する(touchとかで)

[smtp.gmail.com]:587 example@gmail.com:samplepass

そして、postmapコマンドをかけてあげて
sasl_passwd.dbができてることを確認する(一部省略)

/etc/postfix $ “sudo postmap /etc/postfix/sasl_passwd
/etc/postfix $ “ls
sasl_passwd sasl_passwd.db

これでもう一度、postfixにreloadをかけてあげると終わり。

phpの対話シェルとかで

mail("example@exmaple.com", "タイトル", "本文");

で送れてることを確認できればOK!!


とりあえず、ここを参考にしましたー
http://blog.sarabande.jp/post/29081891413
http://weble.org/2012/05/10/mac-postfix